module PolyglotCli::Helper::General

Public Instance Methods

config() click to toggle source
# File lib/polyglot_cli/helpers/general.rb, line 12
def config
  @config ||= PolyglotCli::IO::Config.read
end
languages(locale = nil) click to toggle source
# File lib/polyglot_cli/helpers/general.rb, line 30
def languages(locale = nil)
  prompt.say('Getting languages...')
  select_languages(
    locale,
    PolyglotCli::Resource::Language.with_subdomain(subdomain).token(token).depaginate(project_id: project_id)
  )
end
project() click to toggle source
# File lib/polyglot_cli/helpers/general.rb, line 20
def project
  prompt.say('Getting project...')
  PolyglotCli::Resource::Project.with_subdomain(subdomain).token(token).find(project_id).first
end
project_id() click to toggle source
# File lib/polyglot_cli/helpers/general.rb, line 16
def project_id
  config[:project_id]
end
remote_translations(language) click to toggle source
# File lib/polyglot_cli/helpers/general.rb, line 56
def remote_translations(language)
  prompt.say("Getting #{language.name} translations...")
  PolyglotCli::Resource::Translation.with_subdomain(subdomain).token(token).depaginate(project_id: project_id, language_id: language.id)
end
select_languages(locale, results) click to toggle source
# File lib/polyglot_cli/helpers/general.rb, line 38
def select_languages(locale, results)
  results.select! { |l| l.locale == locale } if locale.present?

  if config[:locale_mapping].present?
    results.select! do |l|
      l.locale = config[:locale_mapping][l.locale]
      l.locale.present?
    end
  end

  results
end
server_changed?() click to toggle source
# File lib/polyglot_cli/helpers/general.rb, line 25
def server_changed?
  return true if config[:project_updated_at].nil?
  Time.parse(project.updated_at).utc > Time.parse(config[:project_updated_at]).utc
end
subdomain() click to toggle source
# File lib/polyglot_cli/helpers/general.rb, line 8
def subdomain
  config[:subdomain]
end
token() click to toggle source
# File lib/polyglot_cli/helpers/general.rb, line 4
def token
  @token ||= PolyglotCli::IO::Token.read
end
update_config() click to toggle source
# File lib/polyglot_cli/helpers/general.rb, line 51
def update_config
  config[:project_updated_at] = project.updated_at
  PolyglotCli::IO::Config.write(config)
end