vwochnik / jekyll-language-plugin

Jekyll 3.0-compatible multi-language plugin for posts, pages and includes
MIT License
115 stars 45 forks source link

Provide pre-translated strings #8

Closed Anthony-Gaudino closed 8 years ago

Anthony-Gaudino commented 8 years ago

How do you like it if I create YAML files containing translated dates, translated language names and maybe other things for most languages?

Rails-i18n provide files with translations for dates and other things.

You will be able to include the files on the plugin or make it available to users, so they can use on their websites.

It would be something like this:


---
en-US:
  language: English
  date:
    abbr_day_names:
    - Sun
    - Mon
    - Tue
    - Wed
    - Thu
    - Fri
    - Sat
    abbr_month_names:
    - Jan
    - Feb
    - Mar
    - Apr
    - May
    - Jun
    - Jul
    - Aug
    - Sep
    - Oct
    - Nov
    - Dec
    day_names:
    - Sunday
    - Monday
    - Tuesday
    - Wednesday
    - Thursday
    - Friday
    - Saturday
    month_names:
    - January
    - February
    - March
    - April
    - May
    - June
    - July
    - August
    - September
    - October
    - November
    - December
    prompts:
      day: Day
      hour: Hour
      minute: Minute
      month: Month
      second: Seconds
      year: Year

So, if someone wants to create a menu with links for all available languages, they can query the language in the YAML and create a list like this:

English
Français
Português

If you want to, you can even automate the plugin to look for the Jekyll date liquid tag and translate the date without the user having to use another liquid tag just for it, but then in this case, the user would need to use the same language names provided by the plugin.

And if you think there's other interesting strings that could be added I will see what I can do.

vwochnik commented 8 years ago

This looks interesting but it defies the simplicity and flexibility of the plugin. For instance, what about users having a language called english instead of en or en-US or en_US. This is all not defined within the plugin.

This is what I would suggest instead: If the i18n-rails gem is present, dynamically load the date and language translations into the plugin. This would make it very maintainable and gives the user options. By any chance, do you know how to retrieve the language data from i18n-rails during runtime?

I have looked at the repository. This looks promising.

vwochnik commented 8 years ago

I have looked at it more extensively and the rails-i18n package does not provide any language names. The only thing I can extract are date formats and day and month names.

vwochnik commented 8 years ago

I have just abstracted the data processing in the plugin and added a loader for rails-i18n. Upgrade to version 1.2.0 and include rails-i18n in your Gemfile. You have all dates available.

Anthony-Gaudino commented 8 years ago

Wow!

I tough would help you on this, but you just nailed it.


I was looking for an alternative for the languages names and found two gems that are specialized in this:

vwochnik commented 8 years ago

Language names and dates are now built-in.

Anthony-Gaudino commented 8 years ago

Nice, I think that adding the languages on the plugin is great, and it's much more simple than having to load it from other gems.

Why didn't you said you wanted to add the language files? I could have helped you.

Can I add the other languages or are you already working on it?

vwochnik commented 8 years ago

I have written a script that imports the languages from the gems you have listed above. The script only imports languages where all data can be extracted from the gems. rails-i18n only provides the language name in one language. i18n-iso639matrix provides language name translations.

Which languages do you want to add? IMO that is enough for this plugin.

Anthony-Gaudino commented 8 years ago

OK, so you used the script to generate all those 27 language files.

Since you are embedding the translations into the plugin it won't require the other gems, right?

vwochnik commented 8 years ago

Exactly. I have only chosen those few languages because I wanted the data to be as complete as possible for every language.

Btw, what other translations did you mean when you said other interesting strings? I have looked at relative time but IMO for a static site that does not make any sense.

Anthony-Gaudino commented 8 years ago

I meant something that could be useful, for example, units or currency.

Unfortunately those gems don't have all strings translated, so some of them will come as English.

vwochnik commented 8 years ago

That's why I will leave the data as it is for now. If you want to, you can add more translations for your own site. You can even add your own loader (but it is not documented yet). Look at Jekyll::LanguagePlugin::Loaders::BuildinDataLoader.

Anthony-Gaudino commented 8 years ago

Ok, I will try to add as many languages I can and then I will open a pull request when I'm done.

vwochnik commented 8 years ago

Make sure that you add the additional language names to all existing languages then. Also, please restrict yourself to ISO369-1 two-letter language codes only.

Anthony-Gaudino commented 8 years ago

OK.

vwochnik commented 8 years ago

Please make your changes in a new branch.

Anthony-Gaudino commented 8 years ago

Sure.