class PolyglotFlutter::Command::Pull
Public Class Methods
init()
click to toggle source
# File lib/flutter_polyglot_cli/commands/pull.rb, line 7 def self.init new.call end
Public Instance Methods
call()
click to toggle source
# File lib/flutter_polyglot_cli/commands/pull.rb, line 11 def call prompt.say('Fetching translations...') generate_translations(project_configs) success('Translations successfully generated!') end
Private Instance Methods
generate_translations(projects)
click to toggle source
# File lib/flutter_polyglot_cli/commands/pull.rb, line 19 def generate_translations(projects) projects.each do |project| project_id = project[:id] flutter_instance = project[:flutterInstance] mandatory_language = project[:mandatoryLanguage] arb_path = project[:path] l10n_path = project[:l10nFilePath] directory_path = project[:sourceFilesPath] output_localization_file = project[:outputLocalizationFile] set_default_langauge = project[:setDefaultLangauge] languages = pull_languages(project_id) translation_keys = pull_translation_keys(project_id) write_translations(translation_keys, languages, arb_path) write_l10n_yaml(l10n_path, arb_path, mandatory_language, output_localization_file) script = "#{flutter_instance} packages get" `#{script}` write_localization(directory_path, languages, output_localization_file, set_default_langauge, mandatory_language) end end
pull_languages(project_id)
click to toggle source
Pulling data
# File lib/flutter_polyglot_cli/commands/pull.rb, line 72 def pull_languages(project_id) PolyglotFlutter::Resource::Language .token(token) .depaginate(project_id: project_id) end
pull_translation_keys(project_id)
click to toggle source
# File lib/flutter_polyglot_cli/commands/pull.rb, line 78 def pull_translation_keys(project_id) PolyglotFlutter::Resource::TranslationKey .token(token) .depaginate(project_id: project_id) .sort_by { |key| key.name.downcase } end
write_l10n_yaml(l10n_path, arb_path, mandatory_language, output_localization_file)
click to toggle source
# File lib/flutter_polyglot_cli/commands/pull.rb, line 55 def write_l10n_yaml(l10n_path, arb_path, mandatory_language, output_localization_file) return if l10n_path.to_s.empty? PolyglotFlutter::IO::L10n .write(l10n_path, arb_path, mandatory_language, output_localization_file) end
write_localization(directory_path, languages, output_localization_file, set_default_langauge, mandatory_language)
click to toggle source
# File lib/flutter_polyglot_cli/commands/pull.rb, line 62 def write_localization(directory_path, languages, output_localization_file, set_default_langauge, mandatory_language) return if directory_path.to_s.empty? PolyglotFlutter::Serializer::Localization::Localization .new(languages: languages) .write(directory_path, output_localization_file, set_default_langauge, mandatory_language) end
write_translations(translation_keys, languages, translations_path)
click to toggle source
Serializing data
# File lib/flutter_polyglot_cli/commands/pull.rb, line 46 def write_translations(translation_keys, languages, translations_path) return if translations_path.to_s.empty? languages.each do |language| PolyglotFlutter::Serializer::Translation .write(translation_keys, language, translations_path) end end