Class: PolyglotIos::Serializer::Translation
- Inherits:
-
Object
- Object
- PolyglotIos::Serializer::Translation
- Defined in:
- lib/ios_polyglot_cli/serializers/translations/translations_serializer.rb
Class Method Summary collapse
- .extract_translations(translation_keys, language) ⇒ Object
- .write(translation_keys, language, translations_path, use_old_naming = false) ⇒ Object
Class Method Details
.extract_translations(translation_keys, language) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/ios_polyglot_cli/serializers/translations/translations_serializer.rb', line 21 def extract_translations(translation_keys, language) translation_keys.each_with_object({}) do |translation_key, strings| key_name = translation_key.name next if key_name.nil? strings[key_name] = translation_key.clean_translation(language) end end |
.write(translation_keys, language, translations_path, use_old_naming = false) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ios_polyglot_cli/serializers/translations/translations_serializer.rb', line 6 def write(translation_keys, language, translations_path, use_old_naming = false) translations = extract_translations(translation_keys, language) data = translations .sort .map { |key, value| "\"#{key}\" = \"#{value}\";" } .join("\n") .concat("\n") FileUtils.mkdir_p translations_path unless File.exist? translations_path locale_code = language.code(use_old_naming) output_path = File.join(translations_path, "#{locale_code}.strings") File.write(output_path, data) end |