agile-france / propile

Community Conference Program Compiler (for Agile France)
2 stars 8 forks source link

Extract localization ressources ? #30

Open dthouvenin opened 10 years ago

dthouvenin commented 10 years ago

I have begun translating the pages into french but that seems a bit silly. I'm a total newbee to RoR but there must be a way that we extract ressources or somehow implement a localization mechanism so that the app becomes multilingual.

I'm a .NET guy. In dotnet we would basically have two options : either use a I18N extension that extract ext litterals at build time into gettext dictionnaries or hack the view rendering engine so that it uses the view based on the local : index.html (generic) index.fr.html (french neutral) index.fr-CA.html (canadian french locale)

I'm pretty sure RoR has plenty of options like this. Anyone willing to address this ?

yaf commented 10 years ago

Rails use YAML file format to manage I18n (https://github.com/agile-france/propile/tree/master/config/locales). File name is not important for I18n process, we can use what we want for our organisation. Inside file, their indetation key, that help for context. To translate a key, just copy the context under a fr: top key. Here is an example:

en:
  date:
    formats:
      default: "%m/%d/%y"
    (... other keys ...)
fr:
  date:
    formats:
      default: "%d/%m/%y"
    (... other keys ...)

Hope it's help.

After, there is some scripts and tools that take those YAML files and do some stuff with, but I don't know lot of them.

yaf commented 10 years ago

But there is no tools to extract char for page. Or I don't know them. It's perhaps an idea to build. But more of the rails dev work directly with i18n keys :-)

oelmekki commented 10 years ago

Hello,

the basic helper for translations is #t, or #translate. If you have this translation file :

# config/locales/layouts.fr.yml
fr:
  layouts:
    main_menu:
      log_in: 'Connexion'

You can use it that way in your view :

<%= t 'layouts.main_menu.log_in %>

Additionally, there are helpers for the current view. If you're in a app/views/contacts/new.html.erb file, you can use this (note the dot at the beginning of the string) :

<%= t '.email' %>

And have this yaml file :

# config/locales/contacts/new.fr.yml
fr:
  contacts:
    new:
      email: 'Adresse mail'

The fact that rails should use contacts.new will be inferred from view file name. This is the relative notation.

oelmekki commented 10 years ago

There are also a few configuration you may want to change in config/application.rb for localization :

All this config are already there (albeit commented for some) in config/application.rb, you just have to change their value / uncomment them.

The very last config is only needed if you want to use subdirectories inside config/locales/ to manage your translations (like config/locales/contacts/new.fr.yml in my previous example).

Edit : Also, please note something somewhat tricky at first in development environment : each time you add a new i18n file, you have to restart rails server for it to be considered (you don't have to restart server if editing existing file).

oelmekki commented 10 years ago

or hack the view rendering engine so that it uses the view based on the local : index.html (generic) index.fr.html (french neutral) index.fr-CA.html (canadian french locale)

Oh, btw. This also works in rails :)

You can have contacts/new.fr.html.erb and contacts/new.en.html.erb, for example.

But since this app won't support dual language (afaik), there's no point in that. I tend to prefer to remove all marketing text from codebase, using yaml files in config/locales/, rather.

dboissier commented 10 years ago

Hi,

With the team, we are agree to work to start I18N migration. The following are top priority:

I can help on that if needed.