Class: PolyglotFlutter::Serializer::Localization::LocalizationStrings

Inherits:
Base
  • Object
show all
Defined in:
lib/flutter_polyglot_cli/serializers/localizations/localization_strings_serializer.rb

Constant Summary

Constants included from Helper::General

Helper::General::ESCAPE_KEYWORDS

Instance Attribute Summary

Attributes inherited from Base

#languages, #translation_keys

Instance Method Summary collapse

Methods inherited from Base

#initialize, #render

Methods included from Helper::General

#clean_enum_name, #clean_variable_name, #config, #escape_keyword_if_needed, #escape_with_underscore_if_needed, #extract_translations, #find_app_language, #generate_locales, #generate_localization_keys, #generate_static_locales, #generate_strings, #indent, #mandatory_language, #programming_language, #project_configs, #token, #use_old_naming

Constructor Details

This class inherits a constructor from PolyglotFlutter::Serializer::Localization::Base

Instance Method Details

#save(sources_path) ⇒ Object



7
8
9
10
11
# File 'lib/flutter_polyglot_cli/serializers/localizations/localization_strings_serializer.rb', line 7

def save(sources_path)
  FileUtils.mkdir_p sources_path unless File.exist? sources_path
  output_path = File.join(sources_path, 'localization_strings.dart')
  File.write(output_path, render)
end

#templateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/flutter_polyglot_cli/serializers/localizations/localization_strings_serializer.rb', line 13

def template
  "  part of 'localization.dart';\n\n  // AUTO GENERATED FILE. DO NOT CHANGE.\n  enum Strings {\n  <%= generate_strings(languages, translation_keys, mandatory_language) %>}\n\n  extension StringsValue on Strings {\n    String value() => toString().split('.').last;\n\n    String localized({BuildContext context, List<Object> args}) {\n      if (context != null) {\n        Localizations.of<Localization>(context, Localization);\n      }\n      return Intl.message('', name: value(), args: args);\n    }\n  }\n  TEMPLATE\nend\n"