Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Extract localization ressources ? #30

Open
dthouvenin opened this issue Nov 21, 2013 · 6 comments
Open

Extract localization ressources ? #30

dthouvenin opened this issue Nov 21, 2013 · 6 comments

Comments

@dthouvenin
Copy link

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
Copy link

yaf commented Nov 21, 2013

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
Copy link

yaf commented Nov 21, 2013

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
Copy link

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
Copy link

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

  • config.time_zone = 'Paris' -> set french timezone
  • config.i18n.default_locale = :fr -> set french as default locale
  • config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s] -> allows subdirectories in config/locales/

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
Copy link

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
Copy link

Hi,

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

  • Session proposal creation page
  • Thanks page (after submitting the above form)
  • Presenters

I can help on that if needed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants