14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/applyrics/cli.rb', line 14
def run
program :name, 'applyrics'
program :version, Applyrics::VERSION
program :description, Applyrics::DESCRIPTION
program :help_formatter, :compact
global_option '--[no-]rebuild', TrueClass, 'Rebuild language files from source'
command :init do |c|
c.syntax = "applyrics init"
c.description = "Setup the project for applyrics"
c.action do |args, options|
project = Applyrics::Project.new()
if project.nil?
puts "Error"
else
case project.platform
when :ios
puts "Located ".green + "iOS".bold.green + " project".green
when :android
puts "Located ".green + "Android".bold.green + " project".green
end
langs = project.detected_languages
puts "Found #{langs.length} languages: #{langs.join(', ')}".green
puts ""
lang_files = project.language_files
langs.each do |lang|
if !lang_files.key?(lang)
puts "[#{lang}] No files detected for language!".yellow
next
end
end
end
end
end
command :extract do |c|
c.syntax = "applyrics extract"
c.description = "Pull strings from the project into a strings.json file"
c.action do |args, options|
project = Applyrics::Project.new()
detect_lang = project.detected_languages
langs = project.string_files()
puts "Found files for #{langs.length} languages".green
if options.rebuild
puts "Rebuilding...".blue
rebuilt = project.rebuild_files()
langs = langs.merge(rebuilt)
puts "Language \"#{project.default_language}\" is rebuilt from source into #{rebuilt[project.default_language].length} files".blue
end
puts "Writing #{langs.length} languages: #{langs.keys.join(', ')}".green
file = LanguageFile.new(File.join("./", "strings.json"), langs)
file.write
end
end
command :apply do |c|
c.syntax = "applyrics apply"
c.description = "Applies language from a .json file"
c.option '--data STRING', String, 'Path to .json file (Default: strings.json)'
c.action do |args, options|
options.default :project => './', :data => './strings.json'
language_file = LanguageFile.new(options.data)
puts "Loaded language file with #{language_file.languages.length} languages".green
project = Applyrics::Project.new()
detect_lang = project.detected_languages
langs = project.string_files()
langs = langs.merge(language_file.to_hash)
project.apply_languages(langs)
end
end
run!
end
|