From 83735a8b175dd04828df59b93a864070074d07c0 Mon Sep 17 00:00:00 2001 From: Marcel Hoppe <5444908+hoppsen@users.noreply.github.com> Date: Tue, 23 Feb 2021 20:20:11 +0400 Subject: [PATCH 1/4] Update lokalise.rb Introduced bundle_structure, export_sort and replace_breaks parameters. --- lokalise.rb | 146 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 85 insertions(+), 61 deletions(-) diff --git a/lokalise.rb b/lokalise.rb index bd9223b..07851a5 100644 --- a/lokalise.rb +++ b/lokalise.rb @@ -10,16 +10,19 @@ def self.run(params) clean_destination = params[:clean_destination] include_comments = params[:include_comments] original_filenames = params[:use_original] + bundle_structure = params[:bundle_structure] ? params[:bundle_structure] : "%LANG_ISO%.lproj/Localizable.%FORMAT%" + export_sort = params[:export_sort] ? params[:export_sort] : "a_z" + replace_breaks = params[:replace_breaks] ? true : false body = { format: "ios_sdk", original_filenames: original_filenames, bundle_filename: "Localization.zip", - bundle_structure: "%LANG_ISO%.lproj/Localizable.%FORMAT%", + bundle_structure: bundle_structure, export_empty_as: "base", - export_sort: "first_added", + export_sort: export_sort, include_comments: include_comments, - replace_breaks: false + replace_breaks: replace_breaks } filter_langs = params[:languages] @@ -83,12 +86,12 @@ def self.unzip_file(file, destination, clean_destination) FileUtils.mkdir_p(destination) end UI.message "Unarchiving localizations to destination 📚" - zip_file.each { |f| - f_path= File.join(destination, f.name) - FileUtils.mkdir_p(File.dirname(f_path)) - FileUtils.rm(f_path) if File.file? f_path - zip_file.extract(f, f_path) - } + zip_file.each { |f| + f_path= File.join(destination, f.name) + FileUtils.mkdir_p(File.dirname(f_path)) + FileUtils.rm(f_path) if File.file? f_path + zip_file.extract(f, f_path) + } } end @@ -104,62 +107,83 @@ def self.description def self.available_options [ FastlaneCore::ConfigItem.new(key: :api_token, - env_name: "LOKALISE_API_TOKEN", - description: "API Token for Lokalise", - verify_block: proc do |value| - UI.user_error! "No API token for Lokalise given, pass using `api_token: 'token'`" unless (value and not value.empty?) - end), + env_name: "LOKALISE_API_TOKEN", + description: "API Token for Lokalise", + verify_block: proc do |value| + UI.user_error! "No API token for Lokalise given, pass using `api_token: 'token'`" unless (value and not value.empty?) + end), FastlaneCore::ConfigItem.new(key: :project_identifier, - env_name: "LOKALISE_PROJECT_ID", - description: "Lokalise Project ID", - verify_block: proc do |value| - UI.user_error! "No Project Identifier for Lokalise given, pass using `project_identifier: 'identifier'`" unless (value and not value.empty?) - end), + env_name: "LOKALISE_PROJECT_ID", + description: "Lokalise Project ID", + verify_block: proc do |value| + UI.user_error! "No Project Identifier for Lokalise given, pass using `project_identifier: 'identifier'`" unless (value and not value.empty?) + end), FastlaneCore::ConfigItem.new(key: :destination, - description: "Localization destination", - verify_block: proc do |value| - UI.user_error! "Things are pretty bad" unless (value and not value.empty?) - UI.user_error! "Directory you passed is in your imagination" unless File.directory?(value) - end), + description: "Localization destination", + verify_block: proc do |value| + UI.user_error! "Things are pretty bad" unless (value and not value.empty?) + UI.user_error! "Directory you passed is in your imagination" unless File.directory?(value) + end), FastlaneCore::ConfigItem.new(key: :clean_destination, - description: "Clean destination folder", - optional: true, - is_string: false, - default_value: false, - verify_block: proc do |value| - UI.user_error! "Clean destination should be true or false" unless [true, false].include? value - end), + description: "Clean destination folder", + optional: true, + is_string: false, + default_value: false, + verify_block: proc do |value| + UI.user_error! "Clean destination should be true or false" unless [true, false].include? value + end), FastlaneCore::ConfigItem.new(key: :languages, - description: "Languages to download", - optional: true, - is_string: false, - verify_block: proc do |value| - UI.user_error! "Language codes should be passed as array" unless value.kind_of? Array - end), - FastlaneCore::ConfigItem.new(key: :include_comments, - description: "Include comments in exported files", - optional: true, - is_string: false, - default_value: false, - verify_block: proc do |value| - UI.user_error! "Include comments should be true or false" unless [true, false].include? value - end), - FastlaneCore::ConfigItem.new(key: :use_original, - description: "Use original filenames/formats (bundle_structure parameter is ignored then)", - optional: true, - is_string: false, - default_value: false, - verify_block: proc do |value| - UI.user_error! "Use original should be true of false." unless [true, false].include?(value) - end), - FastlaneCore::ConfigItem.new(key: :tags, - description: "Include only the keys tagged with a given set of tags", - optional: true, - is_string: false, - verify_block: proc do |value| - UI.user_error! "Tags should be passed as array" unless value.kind_of? Array - end), - + description: "Languages to download", + optional: true, + is_string: false, + verify_block: proc do |value| + UI.user_error! "Language codes should be passed as array" unless value.kind_of? Array + end), + FastlaneCore::ConfigItem.new(key: :include_comments, + description: "Include comments in exported files", + optional: true, + is_string: false, + default_value: false, + verify_block: proc do |value| + UI.user_error! "Include comments should be true or false" unless [true, false].include? value + end), + FastlaneCore::ConfigItem.new(key: :use_original, + description: "Use original filenames/formats (bundle_structure parameter is ignored then)", + optional: true, + is_string: false, + default_value: false, + verify_block: proc do |value| + UI.user_error! "Use original should be true of false." unless [true, false].include?(value) + end), + FastlaneCore::ConfigItem.new(key: :tags, + description: "Include only the keys tagged with a given set of tags", + optional: true, + is_string: false, + verify_block: proc do |value| + UI.user_error! "Tags should be passed as array" unless value.kind_of? Array + end), + FastlaneCore::ConfigItem.new(key: :bundle_structure, + description: "Bundle structure, used when original_filenames set to false. Allowed placeholders are %LANG_ISO%, %LANG_NAME%, %FORMAT% and %PROJECT_NAME%)", + optional: true, + is_string: true, + verify_block: proc do |value| + UI.user_error! "Should be a String" unless value.kind_of? String + end), + FastlaneCore::ConfigItem.new(key: :export_sort, + description: "Export key sort mode. Allowed values are first_added, last_added, last_updated, a_z, z_a", + optional: true, + is_string: true, + verify_block: proc do |value| + UI.user_error! "Should be a String" unless value.kind_of? String + end), + FastlaneCore::ConfigItem.new(key: :replace_breaks, + description: "Replace breaks", + optional: true, + is_string: false, + default_value: false, + verify_block: proc do |value| + UI.user_error! "Replace break should be true or false" unless [true, false].include? value + end), ] end From d41e6cd7ce75f57ec5e1c136c3bffb1e591533d6 Mon Sep 17 00:00:00 2001 From: Marcel Hoppe <5444908+hoppsen@users.noreply.github.com> Date: Tue, 23 Feb 2021 20:24:38 +0400 Subject: [PATCH 2/4] Update README.md Added missing parameters to lokalise action --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index b36ff8d..536697c 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,10 @@ Parameters: - `languages`. Languages to download *(must be passed as array of strings, leave empty to download all)*. - `include_comments`. Include comments in exported files. - `use_original`. Use original filenames/formats. +- `tags`. Include only the keys tagged with a given set of tags. +- `bundle_structure`. Bundle structure, used when original_filenames set to false. Allowed placeholders are %LANG_ISO%, %LANG_NAME%, %FORMAT% and %PROJECT_NAME%). +- `export_sort`. Export key sort mode. Allowed values are `first_added`, `last_added`, `last_updated`, `a_z`, `z_a`. +- `replace_breaks`. Replace breaks. ## lokalise_metadata From 8ad36a89e69fcc14a559ce496a670de6fdf43962 Mon Sep 17 00:00:00 2001 From: Marcel Hoppe <5444908+hoppsen@users.noreply.github.com> Date: Tue, 23 Feb 2021 20:27:01 +0400 Subject: [PATCH 3/4] Update README.md Optimized description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 536697c..ff15e0d 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Parameters: - `include_comments`. Include comments in exported files. - `use_original`. Use original filenames/formats. - `tags`. Include only the keys tagged with a given set of tags. -- `bundle_structure`. Bundle structure, used when original_filenames set to false. Allowed placeholders are %LANG_ISO%, %LANG_NAME%, %FORMAT% and %PROJECT_NAME%). +- `bundle_structure`. Bundle structure, used when original_filenames set to false. Allowed placeholders are `%LANG_ISO%`, `%LANG_NAME%`, `%FORMAT%` and `%PROJECT_NAME%`. - `export_sort`. Export key sort mode. Allowed values are `first_added`, `last_added`, `last_updated`, `a_z`, `z_a`. - `replace_breaks`. Replace breaks. From 9baed955332e603c187dd0a17cc295781a36553e Mon Sep 17 00:00:00 2001 From: Marcel Hoppe <5444908+hoppsen@users.noreply.github.com> Date: Tue, 23 Feb 2021 20:28:16 +0400 Subject: [PATCH 4/4] Update lokalise.rb Reverted default value --- lokalise.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lokalise.rb b/lokalise.rb index 07851a5..4fad00c 100644 --- a/lokalise.rb +++ b/lokalise.rb @@ -11,7 +11,7 @@ def self.run(params) include_comments = params[:include_comments] original_filenames = params[:use_original] bundle_structure = params[:bundle_structure] ? params[:bundle_structure] : "%LANG_ISO%.lproj/Localizable.%FORMAT%" - export_sort = params[:export_sort] ? params[:export_sort] : "a_z" + export_sort = params[:export_sort] ? params[:export_sort] : "first_added" replace_breaks = params[:replace_breaks] ? true : false body = { @@ -163,7 +163,7 @@ def self.available_options UI.user_error! "Tags should be passed as array" unless value.kind_of? Array end), FastlaneCore::ConfigItem.new(key: :bundle_structure, - description: "Bundle structure, used when original_filenames set to false. Allowed placeholders are %LANG_ISO%, %LANG_NAME%, %FORMAT% and %PROJECT_NAME%)", + description: "Bundle structure, used when original_filenames set to false. Allowed placeholders are %LANG_ISO%, %LANG_NAME%, %FORMAT% and %PROJECT_NAME%", optional: true, is_string: true, verify_block: proc do |value|