Think of the following scenario:
You have created your lovely Rails application and managed to get it real. After a period of time it become more and more popular. People around the world love your application. Then somebody start to ask wether you can provide an version in their language. Some active users even made a commitment that they will contribute the translation to their language.
Pretty good news yet, but when you look back to you application code, you already have over hundreds ERB pages with many hard-code text being spread in HTML and ERB tags…
Although Rails > 2.2 provide a handy way of doing I18N by the I18n.translate( t method in helper), Found out all the text need to transfer is a tedious and error-prone task.
Could we make an automatic tool for this boring task? Since if the hard-coded text is written in English, we can conventionally name the key with the same name. (just lowercase it and connected with underline other than space). And the texts need to be translated in ERB seem to have some common attributes: they either exist in the HTML text node or in some helper methods like
Based on the above assumption, My colleague Rainy pair-programming with me the following tool called ready_for_i18n . and release it at Gemcutter. After install it by
gem install ready_for_i18n
ready_for_i18n <you view path> <target path>
Then the tool will transform your view like the screenshot #1(Diff result) and also generate a dictionary
en.yml file looked like screenshot #2.
Have the similar I18N problem? Check it out and any of your comments are welcome here and also on the project home at github .