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

Keys with only 1 level are not added to yaml export #69

Open
jgoetze opened this issue Jun 4, 2015 · 2 comments
Open

Keys with only 1 level are not added to yaml export #69

jgoetze opened this issue Jun 4, 2015 · 2 comments

Comments

@jgoetze
Copy link

jgoetze commented Jun 4, 2015

Hi everyone,
I got issues exporting db translations to yml file.

In my translations I got this object:

#<TranslationCenter::TranslationKey id: 15, name: "empire", category_id: 5, last_accessed: "2015-06-04 15:02:19", en_status: "untranslated", de_status: "translated", created_at: "2015-06-04 14:56:32", updated_at: "2015-06-04 15:02:19">

I tried to export db2yaml for german. It exported everything except translations keys having no "." in their name.

It tried to reproduce this in console and here are my results:

For each key add_to_hash is called and the result hash is passed. In that method add_to_hash_rec(all_translations, levels, lang) is called and current levels are only ["empire"]. That means, level.count == 1. Returned by the method is {"empire"=>"Imperium"} as it should be, but it never gets added to the passed all_translations hash. So with that, it is not part of the export file.

@jgoetze
Copy link
Author

jgoetze commented Jun 4, 2015

I added a filter to add_to_hash, so it doenst call the recursiv function. That works and adds level 1 translations to yml file. But it has duplicate code to recursive function.

# adds a translation key with its translation to a translation yaml hash
# send the hash and the language as parameters
def add_to_hash(all_translations, lang)
  levels = self.name.split('.')

  # check the number of levels in translation name
  if(levels.size > 1) 
    # recursive adding because of multiple levels
    add_to_hash_rec(all_translations, levels, lang.to_s)
  else
    # direct adding 1 level to result 
    translation = self.accepted_translation_in(lang)
    formatted = translation.value
    # in case of arrays remove the unneeded header
    formatted.to_yaml.gsub!("---\n" , '') if formatted.is_a?(Array)

    all_translations[levels.first] = formatted
  end
end

@LaurensN
Copy link

+1 Also having the same problem.

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

No branches or pull requests

2 participants