Module: Tools
Instance Method Summary collapse
- #create_path_from_segment(segment) ⇒ Object
- #platform ⇒ Object
- #platform_extension ⇒ Object
- #read_localizable_file(file) ⇒ Object
- #retrieve_files_in_locale(locale) ⇒ Object
- #retrieve_locales ⇒ Object
- #retrieve_localizable_folder_path ⇒ Object
- #status ⇒ Object
- #write_to_file(path, content) ⇒ Object
Instance Method Details
#create_path_from_segment(segment) ⇒ Object
57 58 59 |
# File 'lib/tools.rb', line 57 def create_path_from_segment(segment) "/#{segment.platform}/#{segment.language}/#{segment.file_name}" end |
#platform ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tools.rb', line 39 def platform ios_folder = Dir.glob("#{Dir.pwd}/**/*#{'.lproj'}").first unless ios_folder.nil? return "ios" end android_folder = Dir.glob("#{Dir.pwd}/**/*#{'.android'}").first unless android_folder.nil? return "android" end raise Error, 'No localizable files in project' if localizable_file_path.nil? end |
#platform_extension ⇒ Object
53 54 55 |
# File 'lib/tools.rb', line 53 def platform_extension platform == 'ios' ? '.lproj' : '.android' end |
#read_localizable_file(file) ⇒ Object
23 24 25 |
# File 'lib/tools.rb', line 23 def read_localizable_file(file) Apfel.parse(file).key_values end |
#retrieve_files_in_locale(locale) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/tools.rb', line 11 def retrieve_files_in_locale(locale) localizable_folder_path = retrieve_localizable_folder_path return nil if localizable_folder_path.nil? Dir.glob("#{localizable_folder_path}/#{locale}#{platform_extension}/*.strings") end |
#retrieve_locales ⇒ Object
18 19 20 21 |
# File 'lib/tools.rb', line 18 def retrieve_locales languages = Dir.glob("#{Dir.pwd}/**/*#{platform_extension}") languages.map { |language| language.split('/').last.split('.').first } end |
#retrieve_localizable_folder_path ⇒ Object
4 5 6 7 8 9 |
# File 'lib/tools.rb', line 4 def retrieve_localizable_folder_path localizable_file_path = Dir.glob("#{Dir.pwd}/**/*#{platform_extension}").first return nil if localizable_file_path.nil? localizable_file_path.gsub(%r{/[^/]+$}, '') end |
#status ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tools.rb', line 27 def status locales = retrieve_locales puts 'Used locales:' for locale in locales files_in_locale = Dir.glob("#{retrieve_localizable_folder_path}/#{locale}.lproj/*.strings") puts "\n_______________ #{locale.upcase} _______________" for file in files_in_locale puts " #{file.split('/').last}" end end end |
#write_to_file(path, content) ⇒ Object
61 62 63 |
# File 'lib/tools.rb', line 61 def write_to_file(path, content) File.open(path, 'w') { |file| file.write(content) } end |