class PhraseApp::Android::PhraseAppClient
Attributes
client[RW]
locale_files[RW]
locales[RW]
project_id[RW]
sub_path[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/phraseapp_android/phrase_app_client.rb, line 13 def initialize(options = {}) credentials = PhraseApp::Auth::Credentials.new token: (options[:token] || ENV['PHRASE_ACCESS_TOKEN']) self.client = PhraseApp::Client.new credentials self.project_id = options[:project_id] || ENV['PHRASE_PROJECT_ID'] self.sub_path = options[:path] find_locales end
Public Instance Methods
locale_file_name(file_name, locale)
click to toggle source
# File lib/phraseapp_android/phrase_app_client.rb, line 34 def locale_file_name(file_name, locale) locale = '-' + locale unless locale.nil? locale_files.find { |f| f.end_with?("values#{locale}/#{file_name}.xml") } end
read_locale_file(file_name, locale)
click to toggle source
# File lib/phraseapp_android/phrase_app_client.rb, line 30 def read_locale_file(file_name, locale) read_xml_file locale_file_name(file_name, locale) end
read_xml_file(file_name)
click to toggle source
# File lib/phraseapp_android/phrase_app_client.rb, line 21 def read_xml_file(file_name) if file_name f = File.open file_name doc = Nokogiri::XML f f.close doc end end
Protected Instance Methods
find_locales()
click to toggle source
# File lib/phraseapp_android/phrase_app_client.rb, line 41 def find_locales self.locale_files = Dir.glob("#{sub_path}**/main/res/values*/{strings,arrays}.xml") self.locales = locale_files .map { |file| file.match(/res\/values[-]*([a-z]+)?\//i)[1] } .compact .uniq end
write_to_file(path, contents)
click to toggle source
# File lib/phraseapp_android/phrase_app_client.rb, line 53 def write_to_file(path, contents) File.open path, 'w' do |f| f.write contents end end
write_xml_to_file(path, doc)
click to toggle source
# File lib/phraseapp_android/phrase_app_client.rb, line 49 def write_xml_to_file(path, doc) write_to_file path, doc.to_xml(ident: 4) end