From 13982b67adc923c65689ff8f919ced804800adb8 Mon Sep 17 00:00:00 2001 From: Nuo Xu Date: Tue, 14 Jan 2025 09:41:22 -0500 Subject: [PATCH 1/3] add a script to push resource file to Crowdin server --- .../App/l10n/tools/push-strings-to-crowdin.sh | 171 ++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100755 ios/brave-ios/App/l10n/tools/push-strings-to-crowdin.sh diff --git a/ios/brave-ios/App/l10n/tools/push-strings-to-crowdin.sh b/ios/brave-ios/App/l10n/tools/push-strings-to-crowdin.sh new file mode 100755 index 000000000000..cbfcc84d0336 --- /dev/null +++ b/ios/brave-ios/App/l10n/tools/push-strings-to-crowdin.sh @@ -0,0 +1,171 @@ +#!/bin/bash +# Copyright (c) 2025 The Brave Authors. All rights reserved. +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this file, +# You can obtain one at https://mozilla.org/MPL/2.0/. + +# Push string changes to Transifex +# +# Error Codes: +# 0 = Success +# 1 = API Token must be set +# 2 = Unauthorized access +# 3 = Failed to export strings from Xcode project +# 4 = Failed to cleanup strings +# 5 = Failed to push string changes to Crowdin + +report_error() +{ + echo $2 + echo $2 >>output.log 2>&1 + cleanup + exit $1 +} + +cleanup() +{ + if [ -e transifex.log ] ; then + cat transifex.log >> output.log + echo >> output.log + rm transifex.log + fi + + if [ -e ../../Client/en.xcloc ]; then + rm -R ../../Client/en.xcloc + fi + + if [ -e en.xliff ] ; then + rm en.xliff + fi +} + +if [ "${TOKEN}" = "" ] ; then + report_error 1 "TOKEN environment variable must be set to \"api\"" +fi + +cd $(dirname "$0") + +echo "Exporting strings from Xcode project..." +(cd ../../ && xcodebuild -exportLocalizations SWIFT_EMIT_LOC_STRINGS=NO) >>output.log 2>&1 +if [ $? != 0 ] ; then + report_error 4 "ERROR: Failed to export strings from Xcode project, please see output.log" +fi + +mv -f ../../Client/en.xcloc/Localized\ Contents/en.xliff . >>output.log 2>&1 + +if [ $? != 0 ] ; then + report_error 3 "ERROR: Failed to export strings from Xcode project, please see output.log" +fi + +echo "Cleaning up strings..." +./xliff-cleanup.py en.xliff +if [ $? != 0 ] ; then + report_error 4 "ERROR: Failed to cleanup strings, please see output.log" +fi + +sed -i '' 's/Shared\/Supporting Files/brave/' en.xliff >>output.log 2>&1 +if [ $? != 0 ] ; then + report_error 4 "ERROR: Failed to cleanup strings, please see output.log" +fi + +crowdin_project_id=33 +crowdin_storage_id=null + +add_storage_id() +{ + FILE_PATH="en.xliff" + result=$(curl --silent \ + -X "POST" "https://brave-software.crowdin.com/api/v2/storages" \ + -H "Authorization: Bearer ${TOKEN}" \ + -H 'Content-Type: application/octet-stream' \ + -H "Crowdin-API-FileName: en.xliff" \ + --data-binary @"$FILE_PATH" + ) + storage_id=$(echo "$result" | jq '.data.id') + echo $storage_id +} + +delete_storage_id() +{ + http_status_code=$(curl --silent -o /dev/null -w "%{http_code}" \ + -X "DELETE" "https://brave-software.crowdin.com/api/v2/storages/$1" \ + -H "Authorization: Bearer ${TOKEN}" \ + -H "Content-Type: application/json" + ) + echo $http_status_code +} + +add_file() +{ + http_status_code=$(curl --silent -o /dev/null -w "%{http_code}" \ + -X "POST" "https://brave-software.crowdin.com/api/v2/projects/$crowdin_project_id/files" \ + -H "Authorization: Bearer ${TOKEN}" \ + -H 'Content-Type: application/json' \ + --data @- << EOF + { + "storageId": $crowdin_storage_id, + "name": "en.xliff", + "type": "xliff" + } +EOF + ) + echo $http_status_code +} + +delete_file() +{ + http_status_code=$(curl --silent -o /dev/null -w "%{http_code}" \ + -X "DELETE" "https://brave-software.crowdin.com/api/v2/projects/$crowdin_project_id/files/$1" \ + -H "Authorization: Bearer ${TOKEN}" \ + -H 'Content-Type: application/json' \ + ) + echo $http_status_code +} + +echo "Creating a storage id in Crowdin..." +crowdin_storage_id=$(add_storage_id) +if [ $crowdin_storage_id == null ] +then + report_error 5 "ERROR: Failed to create a storage id in Crowdin" +else + echo "Crowdin Storage ID: $crowdin_storage_id" +fi + +echo "Checking if there is already a file id for our project in Crowdin..." +file_result=$(curl --silent \ + -X "GET" "https://brave-software.crowdin.com/api/v2/projects/$crowdin_project_id/files" \ + -H "Authorization: Bearer ${TOKEN}" \ + -H "Content-Type: application/json" +) +file_id=$(echo "$file_result" | jq '.data.[0].data.id') +if [ $file_id == null ] +then + echo "No, there is no file. Adding a new file..." + add_file_http_code=$(add_file) + if [ $add_file_http_code != 201 ] + then + report_error 5 "ERROR: Failed to add a file to the project in Crowdin" + else + echo "The new source file has been added to the project in Crowdin" + fi +else + echo "Yes, there is a file id: $file_id. Deleting this file ..." + delete_file_http_code=$(delete_file $file_id) + if [ $delete_file_http_code != 204 ] + then + report_error 5 "ERROR: Failed to delete the existed file in Crowdin" + else + echo "Now, adding a new file ..." + add_file_http_code=$(add_file) + if [ $add_file_http_code != 201 ] + then + report_error 5 "ERROR: Failed to add a file to the project in Crowdin" + else + echo "The new source file has added to the project in Crowdin" + fi + fi +fi + +cleanup + +echo "Successfully pushed string changes to Crowdin" From 92cba54d98cdd46d224fa268682fde425309653c Mon Sep 17 00:00:00 2001 From: Nuo Xu Date: Tue, 14 Jan 2025 09:51:11 -0500 Subject: [PATCH 2/3] update README --- ios/brave-ios/App/l10n/tools/README.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ios/brave-ios/App/l10n/tools/README.md b/ios/brave-ios/App/l10n/tools/README.md index 271f55847208..098027f7f07b 100644 --- a/ios/brave-ios/App/l10n/tools/README.md +++ b/ios/brave-ios/App/l10n/tools/README.md @@ -1,4 +1,16 @@ -# How to contribute translations +# How to push strings to Crowdin +Once your english strings are all up to date. These changes can be pushed to Crowdin for translation by running the following from Terminal: + +``` +cd l10n/ +TOKEN= ./push-strings-to-crowdin.sh +``` + +If there any issues pushing strings to Transifex then these issues are logged to ```output.log``` + +### The API token can be created from Crowdin Dev Portal + +# How to contribute translations via Transifex There are several things you can do to help us internationalize Brave and provide a great experience for everybody @@ -91,4 +103,5 @@ If there any issues pulling translations into the Xcode project then these issue * When importing translations the ```xcodebuild``` command-line tool: * does __not__ allow us to specify where localizations are imported into the project folder structure - * adds duplicate .strings entries to the ```Copy Bundle Resources``` section of ```Build Phases```, which need to be manually removed \ No newline at end of file + * adds duplicate .strings entries to the ```Copy Bundle Resources``` section of ```Build Phases```, which need to be manually removed + From 703406ad7301f0b75556ab25732527ffcc0b75be Mon Sep 17 00:00:00 2001 From: Nuo Xu Date: Wed, 15 Jan 2025 13:07:14 -0500 Subject: [PATCH 3/3] review(kyle) address comments. --- ios/brave-ios/App/l10n/tools/README.md | 8 +++++++- ios/brave-ios/App/l10n/tools/push-strings-to-crowdin.sh | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ios/brave-ios/App/l10n/tools/README.md b/ios/brave-ios/App/l10n/tools/README.md index 098027f7f07b..6d51dcdf75ac 100644 --- a/ios/brave-ios/App/l10n/tools/README.md +++ b/ios/brave-ios/App/l10n/tools/README.md @@ -1,4 +1,9 @@ # How to push strings to Crowdin + +### Prerequisites +This script is using bash jq command-line tool for parsing JSON data. +Make sure jq is installed and added to your PATH + Once your english strings are all up to date. These changes can be pushed to Crowdin for translation by running the following from Terminal: ``` @@ -8,7 +13,8 @@ TOKEN= ./push-strings-to-crowdin.sh If there any issues pushing strings to Transifex then these issues are logged to ```output.log``` -### The API token can be created from Crowdin Dev Portal +### Note +The API token can be created from Crowdin Dev Portal # How to contribute translations via Transifex diff --git a/ios/brave-ios/App/l10n/tools/push-strings-to-crowdin.sh b/ios/brave-ios/App/l10n/tools/push-strings-to-crowdin.sh index cbfcc84d0336..b3b5bebcc556 100755 --- a/ios/brave-ios/App/l10n/tools/push-strings-to-crowdin.sh +++ b/ios/brave-ios/App/l10n/tools/push-strings-to-crowdin.sh @@ -46,7 +46,7 @@ fi cd $(dirname "$0") echo "Exporting strings from Xcode project..." -(cd ../../ && xcodebuild -exportLocalizations SWIFT_EMIT_LOC_STRINGS=NO) >>output.log 2>&1 +(cd ../../ && xcodebuild -exportLocalizations -exportLanguage en SWIFT_EMIT_LOC_STRINGS=NO) >>output.log 2>&1 if [ $? != 0 ] ; then report_error 4 "ERROR: Failed to export strings from Xcode project, please see output.log" fi @@ -69,7 +69,7 @@ if [ $? != 0 ] ; then fi crowdin_project_id=33 -crowdin_storage_id=null +crowdin_storage_id="null" add_storage_id() { @@ -124,7 +124,7 @@ delete_file() echo "Creating a storage id in Crowdin..." crowdin_storage_id=$(add_storage_id) -if [ $crowdin_storage_id == null ] +if [ "$crowdin_storage_id" == "null" ] then report_error 5 "ERROR: Failed to create a storage id in Crowdin" else @@ -138,7 +138,7 @@ file_result=$(curl --silent \ -H "Content-Type: application/json" ) file_id=$(echo "$file_result" | jq '.data.[0].data.id') -if [ $file_id == null ] +if [ "$file_id" == "null" ] then echo "No, there is no file. Adding a new file..." add_file_http_code=$(add_file)