Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced :bundle_structure, :export_sort, and :replace_breaks parameter #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
146 changes: 85 additions & 61 deletions lokalise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] : "first_added"
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]
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down