Skip to content

Commit

Permalink
Add gradle tasks for l10n tasks. (mozilla-mobile#140)
Browse files Browse the repository at this point in the history
(Eventually this could be refactored to be a gradle plugin that we can use for
future apps)
  • Loading branch information
pocmo committed Mar 2, 2017
1 parent fa724d9 commit 03531c4
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .android2po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# That's where we store our exported po files. This directory is added to .gitignore and should not be
# commited to the Focus repository. Usually this is a checkout of the l10n repository:
# https://github.com/mozilla-l10n/focus-android-l10n
--gettext l10n/
--gettext l10n-repo/

# This is following the layout that Pontoon requires:
# https://developer.mozilla.org/en-US/docs/Mozilla/Implementing_Pontoon_in_a_Mozilla_website
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ captures/
*.jks

# Local checkout of localization files
l10n/
l10n-repo/

36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,39 +43,49 @@ Focus for Android is getting localized on [Pontoon](https://pontoon.mozilla.org/
easy_install android2po
```

1. Create a local checkout of the l10n repository into a folder called l10n:
1. Run the `stringsSetup` gradle tasks to create a local checkout of the L10N repository (in folder l10n-repo):

```shell
git clone https://github.com/mozilla-l10n/focus-android-l10n.git l10n
./gradlew stringsSetup
```


### Export strings for translation

1. Run the export command of android2po to generate a new template:
1. Fetch the latest changes from the L10N repository and remove all local modifications with the `stringsCleanUpdate` gradle task:

```shell
./gradlew stringsCleanUpdate
```

1. Run the `stringsExport` gradle task to update the template and existing translations:

```shell
a2po export
./gradlew stringsExport
```

1. Go to the l10n folder, commit and push the updated template to the l10n repository.
1. Create separate commits for every locale using the `stringsCommit` gradle task:

```shell
./gradlew stringsCommit
```

1. Go to the l10n-repo folder, verify the changes and push them to the L10N repository.

### Import translated strings

1. Go to the l10n folder and pull the latest changes:
1. Fetch the latest changes from the L10N repository and remove all local modifications with the `stringsCleanUpdate` gradle task:

```shell
cd l10n
git pull -r
./gradlew stringsCleanUpdate
```

1. Go back to the root folder and run the import command of android2po
1. Run the `stringsImport` gradle task to generate the Android XML files.

```shell
cd ..
a2po import
./gradlew stringsImport
```
1. Commit and push the updated XML files to the app repository.

1. Verify the changes and then commit and push the updated XML files to the app repository.


82 changes: 82 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,85 @@ tasks.whenTaskAdded { task ->
task.dependsOn buildBlocklists
}
}



// -------------------------------------------------------------------------------------------------
// L10N: Initialize Strings
// -------------------------------------------------------------------------------------------------

task stringsSetup(type:Exec) {
group = 'Localization'
description = 'Setup L10N repository for importing and exporting strings.'

workingDir '..'

commandLine 'git', 'clone', 'https://github.com/mozilla-l10n/focus-android-l10n.git', 'l10n-repo'
}

// -------------------------------------------------------------------------------------------------
// L10N: Export Strings
// -------------------------------------------------------------------------------------------------

task stringsExport(type:Exec) {
group = 'Localization'
description = 'Export strings to L10N repository.'

workingDir '..'

commandLine 'a2po', 'export'
}

// -------------------------------------------------------------------------------------------------
// L10N: Import Strings
// -------------------------------------------------------------------------------------------------

task stringsImport {
group = 'Localization'
description = 'Import strings from L10N repository.'

doLast {
exec {
workingDir '..'
commandLine 'a2po', 'import'
}
exec {
workingDir '../tools/l10n/'
commandLine 'sh', 'fix_locale_folders.sh'
}
}
}

// -------------------------------------------------------------------------------------------------
// L10N: Create commits
// -------------------------------------------------------------------------------------------------

task stringsCommit(type:Exec) {
group = 'Localization'
description = 'Create commits for exported strings.'

workingDir '../tools/l10n/'

commandLine 'sh', 'create_commits.sh'
}

// -------------------------------------------------------------------------------------------------
// L10N: Clean and update
// -------------------------------------------------------------------------------------------------

task stringsCleanUpdate() {
group = 'Localization'
description = 'Fetch L10N changes and remove all local modifications.'

doLast {
exec {
workingDir '../l10n-repo/'
commandLine 'git', 'fetch', 'origin'

}
exec {
workingDir '../l10n-repo/'
commandLine 'git', 'reset', '--hard', 'origin/master'
}
}
}
25 changes: 25 additions & 0 deletions tools/l10n/create_commits.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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 http://mozilla.org/MPL/2.0/.

# Create a separate commit for every locale.

parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
cd "$parent_path/../../l10n-repo"

git add locales/templates/app.pot
git commit -m "template update: app.pot"

cd locales

locale_list=$(find . -mindepth 1 -maxdepth 1 -type d \( ! -iname ".*" \) | sed 's|^\./||g' | sort)
for locale in ${locale_list};
do
# Exclude templates
if [ "${locale}" != "templates" ]
then
git add ${locale}/app.po
git commit -m "${locale}: Update app.po"
fi
done

34 changes: 34 additions & 0 deletions tools/l10n/fix_locale_folders.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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 http://mozilla.org/MPL/2.0/.

# a2po has problems with the folder format of Pontoon and creates resource folders
# like values-es-MX. Android expects values-es-rMX. This script tries to find those
# folders and fixes them.

parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )

cd "$parent_path/../../app/src/main/res/"


folder_list=$(find . -maxdepth 1 -type d -iname "values-*-*")
for folder in ${folder_list};
do
country=$(echo ${folder} | cut -d'-' -f3)
len=${#country}

if [ "$len" -eq "2" ]; then
prefix=$(echo ${folder} | cut -d'-' -f1,2)

fixed_folder="${prefix}-r${country}"

echo "Fixing ${folder} -> ${fixed_folder}"

if [ -f $fixed_folder ] ; then
rm -rf "${fixed_folder}"
fi

mv "$folder" "${fixed_folder}"
fi
done

0 comments on commit 03531c4

Please sign in to comment.