Skip to content

Instantly share code, notes, and snippets.

@jcampbell05
Created October 6, 2016 16:13
Show Gist options
  • Save jcampbell05/2e1213ad8c48f89b1fc0806bd4576d3c to your computer and use it in GitHub Desktop.
Save jcampbell05/2e1213ad8c48f89b1fc0806bd4576d3c to your computer and use it in GitHub Desktop.
PO_EDITOR_BASE_LANGUAGE = 'en'
PO_EDITOR_LANGUAGES = ['en', 'fr', 'es', 'pt'].freeze
def export_translations
poeditor_export(
api_token: PO_EDITOR_API_TOKEN,
project_id: PO_EDITOR_PROJECT_ID,
export_format: 'apple_strings',
language: PO_EDITOR_BASE_LANGUAGE,
output_path: "Sup/Base.lproj/Localizable.strings"
)
PO_EDITOR_LANGUAGES.each do |l|
poeditor_export(
api_token: PO_EDITOR_API_TOKEN,
project_id: PO_EDITOR_PROJECT_ID,
export_format: 'apple_strings',
language: l,
output_path: "Sup/#{l}.lproj/Localizable.strings"
)
end
end
desc "Updates the translations files from POEditor.com"
desc "This will do the following: "
desc "- Pull down the latest translations from POEditor.com"
desc "- Preprocess them for use with iOS"
lane :update_translations do
puts "Updating Translations..."
export_translations
files = Dir.glob("../{Sup,Sup-Watch}/**/*.strings")
files.each do |f|
puts "Updating #{f}..."
old_contents = File.read(f)
# Replace %s and %1$s with %@ so that placeholders are displayed
# correctly across Android and iOS
new_contents = old_contents.gsub(/%(?:\d\$)?s/, "%@")
File.open(f, "w") {|file| file.puts new_contents }
end
puts "** #{files.count} Updated! **"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment