scelis / twine

Twine is a command line tool for managing your strings and their translations.
Other
840 stars 151 forks source link

Nested JSON translations unsupported (undefined method gsub for object hash) #296

Closed morinted closed 1 year ago

morinted commented 4 years ago

It seems like the parser for the jQuery localize format doesn't handle nested keys. I'm using i18next which seems to have a similar enough format to work.

Twine version: 1.0.6

Using a sample file from the jQuery-localize docs: https://github.com/coderifous/jquery-localize

{
  "title": "Tracker Pro XT Deluxo",
  "search": {
    "placeholder": "Searcho...",
    "button": "Vamos!"
  },
  "footer": {
    "disclaimer": "Bewaro."
  },
  "menu": {
    "dashboard": "Dashboardo",
    "list": "Bug Listo",
    "logout": "Exito"
  }
}
$ twine consume-all-localization-files twine.txt locales/ --developer-language en --consume-all
NoMethodError: undefined method `gsub' for {"placeholder"=>"Searcho...", "button"=>"Vamos!"}:Hash
  /usr/local/lib/ruby/gems/2.7.0/gems/twine-1.0.6/lib/twine/formatters/abstract.rb:33:in `set_translation_for_key'
  /usr/local/lib/ruby/gems/2.7.0/gems/twine-1.0.6/lib/twine/formatters/jquery.rb:32:in `block in read'
  /usr/local/lib/ruby/gems/2.7.0/gems/twine-1.0.6/lib/twine/formatters/jquery.rb:31:in `each'
  /usr/local/lib/ruby/gems/2.7.0/gems/twine-1.0.6/lib/twine/formatters/jquery.rb:31:in `read'
  /usr/local/lib/ruby/gems/2.7.0/gems/twine-1.0.6/lib/twine/runner.rb:325:in `block in read_localization_file'
  /usr/local/lib/ruby/gems/2.7.0/gems/twine-1.0.6/lib/twine/runner.rb:323:in `open'
  /usr/local/lib/ruby/gems/2.7.0/gems/twine-1.0.6/lib/twine/runner.rb:323:in `read_localization_file'
  /usr/local/lib/ruby/gems/2.7.0/gems/twine-1.0.6/lib/twine/runner.rb:193:in `block in consume_all_localization_files'
  /usr/local/lib/ruby/gems/2.7.0/gems/twine-1.0.6/lib/twine/runner.rb:190:in `glob'
  /usr/local/lib/ruby/gems/2.7.0/gems/twine-1.0.6/lib/twine/runner.rb:190:in `consume_all_localization_files'
  /usr/local/lib/ruby/gems/2.7.0/gems/twine-1.0.6/lib/twine/runner.rb:33:in `run'
  /usr/local/lib/ruby/gems/2.7.0/gems/twine-1.0.6/bin/twine:4:in `<top (required)>'
  /usr/local/lib/ruby/gems/2.7.0/bin/twine:23:in `load'
  /usr/local/lib/ruby/gems/2.7.0/bin/twine:23:in `<top (required)>'

The expected behavior would be to define a twine file like

[[Uncategorized]]
    [title]
      en = Tracker Pro XT Deluxo
    [search.placeholder]
      en = Searcho...
    [search.button]
      en = Vamos!
    [footer.disclaimer]
      en = Bewaro.
    [menu.dashboard]
      en = Dashboardo
    [menu.list]
      en = Bug Listo
    [menu.logout]
      en = Exito

Thank you for your time.

haemi commented 2 years ago

did you find a solution for this?

hooby3dfx commented 1 year ago

Proposed support for this: https://github.com/scelis/twine/pull/314

scelis commented 1 year ago

Fixed in #314

haemi commented 1 year ago

will there be a release with this?

scelis commented 1 year ago

will there be a release with this?

Yeah, I'll find some time to do that today.