-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add a setting for date translations #927
Comments
We might want to use the same solution in Gantry/Grav, we just need to figure out what it would be: |
I just experimented with jenssegers/date and came up with grav-plugin-datetranslations. I setup a test site with a date template:
And a
Please note that I did not provide a page translation to be sure the wrong language wouldn't be picked up. The code is here. Could some people try it out as well? |
I'm not sure if this is enough; to translate time you also need to consider different format from country to country, like 01/31/2016 vs 31.01.2016. |
Well, this is true. But first, that's already a lot better than what we have now in Grav... which is nothing. Second, what you say is actually implementable. There's been a discussion about it, and we could probably implement this solution. That would mean having translation strings for the date formats in every language, and then using these translation strings as format to translate the dates with. It actually makes a lot of sense. The question is just, can we find localized dateFormat strings to work with, or do we have to write our own? See this pull request for some strings. |
One way I have been thinking of, is to have a map of formats like
That would be just a simple translate of the format into another one based on locale. If there's no mapping found, it could just use the one specified. |
Okay I've updated the repo. Now I'm using a You can use the function Could somebody try messing around with it to see if it behaves as expected? |
Hi, Example: This filter is less flexible though. PHP date format characters aren't supported. Update: there is support for a different date pattern. |
@indigoxela not sure if you are aware, the Intl twig extension can be added using https://github.com/Perlkonig/grav-plugin-twig-extensions |
@flaviocopes I am aware of the plugin. |
@indigoxela I added your approach to the Learn site getgrav/grav-learn@cd11517 |
pardon my stupid question, but why not rely on the Intl functions of php ? They handle these details pretty well, and could be used based on the active language IntlDateFormatter |
Sorry for another stupid question but does this mean current version of Grav (1.5) does not handle date translations from scratch? |
Why only "core" Grav? There are Twig extensions that will localize dates. |
Thank you for your answer. I have found this link earlier in the issue. Why only "core" Grav? Because "core" Grav manage – or is said to manage or have to manage – multilanguage. And it appear to not be true. The effort has been stopped before reaching the final goal. Of course one with few skills can do the trick using Twig or PHP but this is not the point. From scratch Grav does not achieve it completely and skills are needed to reach the goal. So this is not easy for common people. |
By default, dates are not translated in Grav, which is a concern for internationalization.
Translating dates is a challenge, but jenssegers/date does it very well. Otherwise, we can hack around with regex, like I did here.
The thing is once the site admin has changed the default dateformat to match their language, we don't have so much to translate.
The [date] page in the PHP manual lists the following things to translate:
Please note that
a
andA
(am/pm) don't need translation as it's mostly an English-speaking concern.S would be the most difficult parameter to translate due
The question is, can we have a core setting to enable/disable date translations, so each subproject doesn't need its own setting for this?
If we can get a core setting for date translations, I'll be glad to write a Twig function to handle this and PR translated dates support in Antimatter and archives plugin.
The text was updated successfully, but these errors were encountered: