class PolyglotIos::Command::Pull

Public Class Methods

init() click to toggle source
# File lib/ios_polyglot_cli/commands/pull.rb, line 7
def self.init
  new.call
end

Public Instance Methods

call() click to toggle source
# File lib/ios_polyglot_cli/commands/pull.rb, line 11
def call
  prompt.say("Fetching translations...")
  generate_translations(project_configs, programming_language)
  success("Translations successfully generated!")
end

Private Instance Methods

generate_translations(projects, programming_language) click to toggle source
# File lib/ios_polyglot_cli/commands/pull.rb, line 19
def generate_translations(projects, programming_language)
  projects.each do |project|
    project_id = project[:id]
    languages = pull_languages(project_id)
    translation_keys = pull_translation_keys(project_id)
    
    write_translations(translation_keys, languages, project[:path], project[:useOldNaming])
    write_languages(languages, project[:sourceFilesPath], programming_language)
    write_translation_sources(translation_keys, project[:sourceFilesPath], programming_language)
  end
end
pull_languages(project_id) click to toggle source

Pulling data

# File lib/ios_polyglot_cli/commands/pull.rb, line 66
def pull_languages(project_id)
  PolyglotIos::Resource::Language
    .token(token)
    .depaginate(project_id: project_id)
end
pull_translation_keys(project_id) click to toggle source
# File lib/ios_polyglot_cli/commands/pull.rb, line 72
def pull_translation_keys(project_id)
  PolyglotIos::Resource::TranslationKey
    .token(token)
    .depaginate(project_id: project_id)
    .sort_by { |key| key.name.downcase }
end
write_languages(languages, sources_path, programming_language) click to toggle source
# File lib/ios_polyglot_cli/commands/pull.rb, line 42
def write_languages(languages, sources_path, programming_language)
  return if sources_path.to_s.empty?
  case programming_language.downcase
  when "objc"
    serializer = PolyglotIos::Serializer::Language::ObjC
  when "swift"
    serializer = PolyglotIos::Serializer::Language::Swift
  end
  serializer.new(languages).save(sources_path)
end
write_translation_sources(translation_keys, sources_path, programming_language) click to toggle source
# File lib/ios_polyglot_cli/commands/pull.rb, line 53
def write_translation_sources(translation_keys, sources_path, programming_language)
  return if sources_path.to_s.empty?
  case programming_language.downcase
  when "swift"
    serializer = PolyglotIos::Serializer::Source::Swift
    serializer
      .new(translation_keys)
      .save(sources_path)
  end
end
write_translations(translation_keys, languages, translations_path, use_old_naming = false) click to toggle source

Serializing data

# File lib/ios_polyglot_cli/commands/pull.rb, line 33
def write_translations(translation_keys, languages, translations_path, use_old_naming = false)
  return if translations_path.to_s.empty?
  languages.each do |language|
    PolyglotIos::Serializer::Translation
      .write(translation_keys, language, translations_path, use_old_naming)
  end

end