-
Notifications
You must be signed in to change notification settings - Fork 895
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
feat(ios): Add a script to push localization resource file to Crowdin #27230
Open
nuo-xu
wants to merge
2
commits into
master
Choose a base branch
from
ios/crowdin-push-strings
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+186
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
ios/brave-ios/App/l10n/tools/push-strings-to-crowdin.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think |
||
if [ $file_id == null ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this checking for the string literal "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" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we only ever push up the
en.xliff
why dont we just only export english here? (-exportLanguage en
)