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

Optionally retain custom structure of locale files #57

Closed
mbusch opened this issue Apr 16, 2014 · 2 comments
Closed

Optionally retain custom structure of locale files #57

mbusch opened this issue Apr 16, 2014 · 2 comments

Comments

@mbusch
Copy link

mbusch commented Apr 16, 2014

If an application exceeds a certain amount of complexity, dealing with I18n keys within just a few files becomes quite unhandy. For that reason the official Rails guide recommends a way to organize the locale files for an affected application (http://guides.rubyonrails.org/i18n.html#organization-of-locale-files).

I played around a bit (like trial-and-error) with the data-write settings within the config file. But to me it seems like it isn't part of the scope yet to just read the original files, decide which keys are missing in the target locale and create the corresponding files and/or keys on the respective folder level.

Is there any possibility to achieve this? Do you think that this is a use case worth considering in the i18n-tasks workflow?

To be clear: Reading the data from this custom structure is easily done - obviously.

# config/i18n-tasks.yml
# ...
data:
  read:
    - 'config/locales/defaults/%{locale}.yml'
    - 'config/locales/defaults/%{locale}.*.yml'
    - 'config/locales/models/*/%{locale}.yml'
    - 'config/locales/views/*/%{locale}.yml'
# ...
@glebm
Copy link
Owner

glebm commented Apr 16, 2014

Your use case only explicit routing is supported, but it is quite flexible. See data.write section in example in the Readme:

# config/i18n-tasks.yml
data:
  write:
    # store sorcery and simple_form keys in the respective files:
    - ['{sorcery,simple_form}.*', 'config/locales/\1.%{locale}.yml']
    # write every key namespace to its own file:
    - ['{:}.*', 'config/locales/\1.%{locale}.yml'] 

However, automatically detecting structure would be super cool. To begin with we could make it a separate task, something like:

$ i18n-tasks detect-structure config/locales
- ['{auth,my}.*', '\1.%{locale}.yml']
- ['*', '%{locale}.yml']

@glebm
Copy link
Owner

glebm commented May 31, 2014

I refactored i18n-tasks to use real trees internally, as opposed to nested hashes.
This, in turn, allowed for a very easy conservative router implementation.

Try it out by switching to master and changing the config to use it:

data:
  router: 'conservative_router'

@glebm glebm closed this as completed Jun 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants