Skip to content

Commit 383d3dc

Browse files
committed
refactor, added android support [ci skip]
1 parent 13d1a81 commit 383d3dc

File tree

1 file changed

+47
-20
lines changed

1 file changed

+47
-20
lines changed

fastlane/actions/localizr.rb

+47-20
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,50 @@ module Actions
33

44
class LocalizrAction < Action
55

6-
def self.localizr_request(server_url, app_slug, locale_code, auth_token, lproj_target_path, lproj_name)
7-
lproj_folder = "#{lproj_target_path}/#{lproj_name}.lproj"
8-
sh "mkdir -p #{lproj_folder}"
9-
sh "curl --fail --silent -o #{lproj_folder}/Localizable.strings #{server_url}/app/#{app_slug}.#{locale_code}?format=ios -H 'Authorization: Token #{auth_token}'"
6+
def self.localizr_request(server_url, app_slug, locale_code, base_locale_code, auth_token, output_target_path, platform)
7+
8+
locale_folder_path = ""
9+
localized_file = ""
10+
11+
case platform
12+
when "ios"
13+
lproj_name = locale_code.strip
14+
if locale_code.downcase.strip == base_locale_code.downcase.strip
15+
lproj_name = 'Base'
16+
end
17+
locale_folder_path = "#{output_target_path}/#{lproj_name}.lproj"
18+
localized_file = "#{locale_folder_path}/Localizable.strings"
19+
when "android"
20+
strings_folder = "values-#{locale_code.strip}"
21+
if locale_code.downcase.strip == base_locale_code.downcase.strip
22+
strings_folder = "values"
23+
end
24+
locale_folder_path = "#{output_target_path}/#{strings_folder}"
25+
localized_file = "#{locale_folder_path}/strings.xml"
26+
end
27+
28+
sh "mkdir -p #{locale_folder_path}"
29+
sh "curl --fail --silent -o #{localized_file} #{server_url}/app/#{app_slug}.#{locale_code}?format=#{platform} -H 'Authorization: Token #{auth_token}'"
1030
end
1131

1232
def self.run(params)
33+
UI.message "Platform: #{params[:platform]}"
1334
UI.message "Server URL: #{params[:localizr_server]}"
1435
UI.message "Base Locale code: #{params[:base_locale_code]}"
1536
UI.message "Locale codes: #{params[:locale_codes]}"
16-
UI.message "LProj Target path: #{params[:lproj_target_path]}"
37+
UI.message "Output Target path: #{params[:output_target_path]}"
1738

1839
params[:locale_codes].split(",").each { |locale_code|
19-
lproj_name = locale_code.strip
20-
if locale_code.downcase.strip == params[:base_locale_code].downcase.strip
21-
lproj_name = 'Base'
22-
end
23-
24-
localizr_request(params[:localizr_server],
40+
41+
localizr_request(
42+
params[:localizr_server],
2543
params[:localizr_app_slug],
26-
locale_code,
44+
locale_code,
45+
params[:base_locale_code],
2746
params[:localizr_api_token],
28-
params[:lproj_target_path],
29-
lproj_name)
47+
params[:output_target_path],
48+
params[:platform],
49+
)
3050
}
3151
rescue
3252
UI.user_error!("An error occured on localizr. Please verify the configuration and then try again.")
@@ -41,7 +61,7 @@ def self.description
4161
end
4262

4363
def self.details
44-
"Localizr is a DSL that handles and automates localization files. Basically we give limited access to the translators to let them input or upload different keystrings and we developer will just fetch it on development or deployment only when if there is an update. This will lessen or prevent the mistake that developer made because he/she has no clue what are those words is and most of them (including me, but not all) are just copy pasting those words (especially when it comes to chinese or japanese characters) from excel to the Localizable.strings via Xcode."
64+
"Localizr is a DSL that handles and automates localization files. Basically we give limited access to the translators to let them input or upload different keystrings and developer will just fetch it on development or deployment only when if there is an update. This will lessen or prevent the mistake that developer made because he/she has no clue what are those words are and most of them (including me, but not all) are just copy-pasting those words (especially when it comes to chinese or japanese characters) from excel to the Localizable.strings via Xcode."
4565
end
4666

4767
def self.available_options
@@ -74,11 +94,18 @@ def self.available_options
7494
verify_block: proc do |value|
7595
UI.user_error!("No Locale codes for LocalizrAction given, pass using `locale_codes: 'en,ja,pt,zh'") unless (value and not value.empty?)
7696
end),
77-
FastlaneCore::ConfigItem.new(key: :lproj_target_path,
78-
env_name: "FL_LOCALIZR_LPROJ_TARGET_PATH",
79-
description: "Lproj target path for LocalizrAction",
97+
98+
FastlaneCore::ConfigItem.new(key: :platform,
99+
env_name: "FL_LOCALIZR_PLATFORM",
100+
description: "Platform for LocalizrAction",
101+
verify_block: proc do |value|
102+
UI.user_error!("No platform for LocalizrAction given, pass using `platform: 'ios'") unless (value and not value.empty?)
103+
end),
104+
FastlaneCore::ConfigItem.new(key: :output_target_path,
105+
env_name: "FL_LOCALIZR_OUTPUT_TARGET_PATH",
106+
description: "Output target path for LocalizrAction",
80107
verify_block: proc do |value|
81-
UI.user_error!("No lproj_target_path for LocalizrAction given, pass using `lproj_target_path: 'Project'") unless (value and not value.empty?)
108+
UI.user_error!("No output_target_path for LocalizrAction given, pass using `output_target_path: 'Project'") unless (value and not value.empty?)
82109
end),
83110
]
84111
end
@@ -88,7 +115,7 @@ def self.authors
88115
end
89116

90117
def self.is_supported?(platform)
91-
platform == :ios
118+
platform == :ios || platform == :android
92119
end
93120
end
94121
end

0 commit comments

Comments
 (0)