Class: PolyglotFlutter::Serializer::Translation
- Inherits:
-
Object
- Object
- PolyglotFlutter::Serializer::Translation
- Extended by:
- Helper::General
- Defined in:
- lib/flutter_polyglot_cli/serializers/translations/translations_serializer.rb
Constant Summary
Constants included from Helper::General
Helper::General::ESCAPE_KEYWORDS
Class Method Summary collapse
Methods included from Helper::General
clean_enum_name, clean_variable_name, config, escape_keyword_if_needed, escape_with_underscore_if_needed, extract_translations, generate_locales, generate_localization_keys, indent, mandatory_language, programming_language, project_configs, token, use_old_naming
Class Method Details
.write(translation_keys, language, translations_path) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/flutter_polyglot_cli/serializers/translations/translations_serializer.rb', line 6 def write(translation_keys, language, translations_path) translations = extract_translations(translation_keys, language) data = translations .sort .map { |key, value| "\t\"#{clean_variable_name(key)}\": \"#{value.gsub(/\n/, '\\n').gsub(/"/, '\\"')}\",\n\t\"@#{clean_variable_name(key)}\": { \"type\": \"text\" }" } .join(",\n") .concat("\n") data = "{\n\t\"@@locale\": \"#{language['locale'].split('_').first}\",\n#{data}}" unless File.exist? translations_path FileUtils.mkdir_p translations_path end locale_code = language.code(true) output_path = File.join(translations_path, "intl_#{locale_code}.arb") File.write(output_path, data) end |