0

I have a big Rails app that I've I18ned. It hasn't yet been translated to any language, but I extracted 99% of the strings into yaml. They come from all over the place - views, models, JS.

There's that remaining 1%, and tracking it down is proving tricky.

I would like to take my existing yaml files and "translate" them into a new language, Lorem Ipsum. I.e, to run the files through some processor that would produce valid i18n locale YAML, with gibberish content.

I would then import these, switch to the test locale (I could call these es.yml, or whatever) and cruise through my app looking for broken formatting and English-language strings.

The only slight problem is... how do I produce this lorem ipsum file? I can't just lorem all of the quoted strings, because there are I18n tokens of several format there.

Any ideas/advice would be appreciated.

ezuk
  • 3,096
  • 3
  • 30
  • 41
  • How about just override the `I18n` methods to produce the gibberish? – rossta Aug 06 '14 at 11:46
  • Interesting idea, thank you! But then how would the generated lorem ipsum correspond in length to the yaml values? – ezuk Aug 06 '14 at 12:59
  • Your method could interpret the length of the actual result and return a lorem ipsum string of the same length. See my answer below. – rossta Aug 06 '14 at 14:12

1 Answers1

1

Here, I'm overriding I18n#translate to return lorem ipsum of the expected text length. I haven't tested this, but in theory, it would look something like this:

module I18n

  alias_method :translate_without_lorem_ipsum, :translate

  def translate_with_lorem_ipsum(*args)
    actual_text = translate_without_lorem_ipsum(*args)
    LoremIpsum.text_with_length(actual_text.length) # imaginary method returning text of given length
  end

  alias_method :translate, :translate_with_lorem_ipsum

end

Since you're using rails, you could replace the alias_method usage with alias_method_chain.

rossta
  • 11,394
  • 1
  • 43
  • 47