Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/i18n localize #783

Merged
merged 5 commits into from
Aug 20, 2023
Merged

Conversation

akarzim
Copy link
Contributor

@akarzim akarzim commented Jul 13, 2023

This is a 🐛 bug fix.
This is a 🙋 feature or enhancement.

Summary

This pull request fixes, enhances and tests i18n liquid tags & filters.

Context

Localization

The newly introduced localization (#759) liquid filter & tag does not work, because I18n.l requires an argument that responds to #strftime, which is not the case for String.

This PR relies on Liquid::Utils.to_date to handle date strings.

And localization filter & tag now support arguments and are fully tested.

Usage:

- {{ data.date | l }}
- {{ data.date | l: "short" }}
- {{ data.date | l: "short", "eo" }}
- {{ data.date | l: "eo" }}

- {{ "now" | l }}
- {{ "now" | l: "short" }}
- {{ "now" | l: "short", "eo" }}
- {{ "now" | l: "eo" }}

- {{ "today" | l }}
- {{ "today" | l: "short" }}
- {{ "today" | l: "short", "eo" }}
- {{ "today" | l: "eo" }}

- {{ 1234567890 | l }}
- {{ 1234567890 | l: "short" }}
- {{ 1234567890 | l: "short", "eo" }}
- {{ 1234567890 | l: "eo" }}
- {% l 1995-12-21 %}
- {% l 1995-12-21 short %}
- {% l 1995-12-21 short eo %}
- {% l 1995-12-21 eo %}

- {% l now %}
- {% l now short %}
- {% l now short eo %}
- {% l now eo %}

- {% l today %}
- {% l today short %}
- {% l today short eo %}
- {% l today eo %}

- {% l 11:22:33 %}
- {% l 11:22:33 short %}
- {% l 11:22:33 short eo %}
- {% l 11:22:33 eo %}

- {% l 1995-12-21T11:22:33 %}
- {% l 1995-12-21T11:22:33 short %}
- {% l 1995-12-21T11:22:33 short eo %}
- {% l 1995-12-21T11:22:33 eo %}

- {% l 1234567890 %}
- {% l 1234567890 short %}
- {% l 1234567890 short eo %}
- {% l 1234567890 eo %}

Note: l tag arguments are split by a space, so datetime must not contain a space character.

Translation

Translation tag & filter now accept arguments too, and are fully tested.

Usage:

- {{ "date.day_names" | t | last }}
- {{ "date.day_names" | t: "locale:eo" | last }}
- {{ "day_names" | t: "scope:date,locale:eo" | last }}
- {{ "missing" | t: "default:oops" }}
- {{ "datetime.distance_in_words.about_x_hours" | t: "count:3" }}
- {{ "datetime.distance_in_words.about_x_hours" | t: "count:1,locale:eo" }}

- {% t errors.messages.not_a_number %}
- {% t errors.messages.not_a_number locale:eo %}
- {% t messages.not_a_number scope:errors,locale:eo %}
- {% t missing default:oops %}
- {% t datetime.distance_in_words.about_x_hours count:3 %}
- {% t datetime.distance_in_words.about_x_hours count:1,locale:eo %}

Note: t tag & filter arguments are key:value pairs separated by commas.

@akarzim akarzim changed the title Faeture/i18n localize Feature/i18n localize Jul 13, 2023
@jaredcwhite
Copy link
Member

Thanks @akarzim! I'll prioritize this for the next release and will review soon.

@jaredcwhite
Copy link
Member

This is great work @akarzim. I will GTM!

@jaredcwhite jaredcwhite merged commit 8b419e4 into bridgetownrb:main Aug 20, 2023
@akarzim akarzim deleted the faeture/i18n-localize branch November 8, 2023 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants