Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ff7c03a
Use i18n update script when generating JS bundle
fluiddot Dec 29, 2021
6e241e1
Remove makepot commands and no longer needed scripts
fluiddot Dec 29, 2021
3e66063
Remove translation files of jetpack and layout-grid
fluiddot Dec 29, 2021
6693dda
Use translation files from i18n-cache folder
fluiddot Dec 29, 2021
5405d5d
Update localization strings files
fluiddot Dec 29, 2021
109eb44
Merge branch 'add/i18n-update-script' into add/use-i18n-update-on-bundle
fluiddot Dec 30, 2021
b015a64
Update localization strings files
fluiddot Dec 30, 2021
7d5a272
Merge branch 'add/i18n-update-script' into add/use-i18n-update-on-bundle
fluiddot Jan 5, 2022
3fc857a
Update android-build-image docker image version
fluiddot Jan 5, 2022
5d65aff
Add skip if cache option to i18n update script
fluiddot Jan 5, 2022
3a68754
Update .gitignore
fluiddot Jan 5, 2022
3c3bb03
Attach i18n update to postinstall command
fluiddot Jan 5, 2022
b423c75
Extract update gutenberg i18n cache to a function
fluiddot Jan 5, 2022
f89eb16
Fix i18n update upon dependencies install
fluiddot Jan 5, 2022
fb9e3f5
Update i18n cache path in CircleCI jobs
fluiddot Jan 5, 2022
45422de
Update gb-mobile-image docker image version
fluiddot Jan 5, 2022
9af4de6
Add i18n check cache script
fluiddot Jan 7, 2022
535b7ee
Update script description
fluiddot Jan 7, 2022
0832eda
Update Gutenberg ref
fluiddot Jan 7, 2022
144a07d
Add WP_CLI_ALLOW_ROOT env variable to pipeline
fluiddot Jan 7, 2022
9c998ce
Update gb-mobile-image version for testing
fluiddot Jan 7, 2022
c68a1b3
Update Gutenberg ref
fluiddot Jan 7, 2022
40fa739
Use latest gb-mobile-image version
fluiddot Jan 10, 2022
b0c47c9
Update Gutenberg ref
fluiddot Jan 10, 2022
7350438
Merge branch 'develop' into add/use-i18n-update-on-bundle
fluiddot Jan 10, 2022
2f735a6
Remove wrong parameter validation
fluiddot Jan 11, 2022
c44a212
Remove unnecessary plugin_name parameter
fluiddot Jan 11, 2022
6e81af1
Update Gutenberg ref with merge commit
fluiddot Jan 11, 2022
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
3 changes: 3 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ steps:
image: "public.ecr.aws/automattic/gb-mobile-image:latest"
environment:
- "CI=true"
# Allow WP-CLI to be run as root, otherwise it throws an exception.
# Reference: https://git.io/J9q2S
- "WP_CLI_ALLOW_ROOT=true"
command: |
source /root/.bashrc

Expand Down
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ commands:
key: npm-i18n-v5-cache-v{{ .Environment.CACHE_TRIGGER_VERSION }}-job-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package-lock.json" }}
paths:
- ~/.npm
- i18n-cache/data
- src/i18n-cache
npm-install-full:
steps:
- restore_cache:
Expand All @@ -39,7 +39,7 @@ commands:
key: npm-i18n-v5-cache-v{{ .Environment.CACHE_TRIGGER_VERSION }}-job-{{ .Environment.CIRCLE_JOB }}-{{ checksum "gutenberg/package-lock.json" }}
paths:
- ~/.npm
- i18n-cache/data
- src/i18n-cache
checkout-shallow:
steps:
- run:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,6 @@ bin/wp-cli.phar

ios/Pods
ios/vendor

# i18n update
i18n-test/
Comment on lines +124 to +125
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a test folder we could use when testing the i18n update command.

68 changes: 68 additions & 0 deletions bin/i18n-check-cache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash
#
# Checks i18n cache folders in order to guarantee that translations are present for provided plugins.
# A cache folder will be created, in case a plugin doesn't have it, with its translations that
# will be fetched before creation.
#
# NOTE: The translations fetched are NOT OPTIMIZED, the reason for this is purely for making
# the script fast as it will be mainly used upon dependency installation.

# Exit if any command fails
set -euo pipefail

function error() {
echo -e "\033[0;31m$1\033[0m"
exit 1
}

function arrayLength() { echo "$#"; }

function check_plugin_cache() {
local plugin_name=$1
local i18n_cache_folder="$TRANSLATIONS_OUTPUT_PATH/$plugin_name"

if [[ ! -d $i18n_cache_folder ]]; then
NOT_FOUND_PLUGIN_I18N_CACHE+=( $i18n_cache_folder )
echo -e "Couldn't find i18n cache folder (\"$i18n_cache_folder\") for plugin \"$plugin_name\", downloading un-optimized translations for creating the cache."
fetch_translations "$plugin_name" "$TRANSLATIONS_OUTPUT_PATH"
fi
}

function update_gutenberg_i18n_cache() {
local output_path=$1

echo "Update \"react-native-editor\" package i18n cache"
cp -r "$output_path/gutenberg/data" gutenberg/packages/react-native-editor/i18n-cache
cp "$output_path/gutenberg/index.js" gutenberg/packages/react-native-editor/i18n-cache/index.native.js
}

function fetch_translations() {
local plugin_name=$1
local output_path=$2

echo -e "\n\033[1mDownload I18n translations for \"$plugin_name\" plugin\033[0m"
node gutenberg/packages/react-native-editor/bin/i18n-translations-download "$plugin_name" "$output_path"
}

# Get parameters
PLUGINS=( "$@" )

# Define constants
TRANSLATIONS_OUTPUT_PATH="src/i18n-cache"

echo -e "\n\033[1m== Checking i18n cache ==\033[0m"

# Check plugins cache
for PLUGIN in "${PLUGINS[@]+"${PLUGINS[@]}"}"; do
check_plugin_cache "$PLUGIN"
done

# Check Gutenberg cache
check_plugin_cache "gutenberg"

if [[ $(arrayLength "${NOT_FOUND_PLUGIN_I18N_CACHE[@]+"${NOT_FOUND_PLUGIN_I18N_CACHE[@]}"}") -eq 0 ]]; then
echo -e "i18n cache for provided plugins is present ✅"
fi

# We need to guarantee that i18n cache within react-native-editor package is updated
update_gutenberg_i18n_cache "$TRANSLATIONS_OUTPUT_PATH"
11 changes: 0 additions & 11 deletions bin/i18n-download.sh

This file was deleted.

45 changes: 30 additions & 15 deletions bin/i18n-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,15 @@ while test $# -gt 0; do
case "$1" in
-h|--help)
echo "options:"
echo "-h, --help show brief help"
echo "-p, --path local path for generating files (by default a temp folder will be used)"
echo "-d, --debug print extra info for debugging"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the debug option as it wasn't being used.

echo "-h, --help show brief help"
echo "-p, --path local path for generating files (by default a temp folder will be used)"
exit 0
;;
-p|--path*)
shift
LOCAL_PATH=$1
shift
;;
-d|--debug*)
shift
DEBUG='true'
;;
*)
break
;;
Expand All @@ -54,6 +49,23 @@ function error() {

function arrayLength() { echo "$#"; }

function check_plugin() {
local plugin_folder=$1

if [[ ! -d $plugin_folder ]]; then
NOT_FOUND_PLUGIN_FOLDERS+=( $plugin_folder )
echo -e "\033[0;31mPlugin folder \"$plugin_folder\" doesn't exist.\033[0m"
fi
}

function update_gutenberg_i18n_cache() {
local output_path=$1

echo "Update \"react-native-editor\" package i18n cache"
cp -r "$output_path/gutenberg/data" gutenberg/packages/react-native-editor/i18n-cache
cp "$output_path/gutenberg/index.js" gutenberg/packages/react-native-editor/i18n-cache/index.native.js
}

function fetch_translations() {
local plugin_name=$1
local output_path=$2
Expand All @@ -63,9 +75,7 @@ function fetch_translations() {
node gutenberg/packages/react-native-editor/bin/i18n-translations-download "$plugin_name" "$output_path" "$used_strings_file"

if [[ "$plugin_name" == "gutenberg" ]]; then
echo "Update \"react-native-editor\" package i18n cache"
cp -r "$output_path/gutenberg/data" gutenberg/packages/react-native-editor/i18n-cache
cp "$output_path/gutenberg/index.js" gutenberg/packages/react-native-editor/i18n-cache/index.native.js
update_gutenberg_i18n_cache "$output_path"
fi
}

Expand All @@ -80,21 +90,27 @@ fi
# Get parameters
PLUGINS=( "$@" )

# Define constants
TRANSLATIONS_OUTPUT_PATH="src/i18n-cache"

echo -e "\n\033[1m== Updating i18n localizations ==\033[0m"

# Validate parameters
if [[ $((${#PLUGINS[@]}%2)) -ne 0 ]]; then
error "Plugin arguments must be supplied as tuples (i.e. domain path/to/plugin)."
fi

# Check plugins parameters
for (( index=0; index<${#PLUGINS[@]}; index+=2 )); do
PLUGIN_FOLDER=${PLUGINS[index+1]}

if [[ ! -d $PLUGIN_FOLDER ]]; then
NOT_FOUND_PLUGIN_FOLDERS+=( $PLUGIN_FOLDER )
echo -e "\033[0;31mPlugin folder \"$PLUGIN_FOLDER\" doesn't exist.\033[0m"
fi
check_plugin "$PLUGIN_FOLDER"
done

# Check Gutenberg plugin
check_plugin "./gutenberg"

# Stop if can't find any plugin folder
if [[ $(arrayLength "${NOT_FOUND_PLUGIN_FOLDERS[@]+"${NOT_FOUND_PLUGIN_FOLDERS[@]}"}") -gt 0 ]]; then
exit 1
fi
Expand All @@ -110,7 +126,6 @@ npm run build:gutenberg
METRO_CONFIG="metro.config.js" node gutenberg/packages/react-native-editor/bin/extract-used-strings "$USED_STRINGS_PATH" "${PLUGINS[@]}"

# Download translations of plugins (i.e. Jetpack)
TRANSLATIONS_OUTPUT_PATH="src/i18n-cache"
for (( index=0; index<${#PLUGINS[@]}; index+=2 )); do
PLUGIN_NAME=${PLUGINS[index]}

Expand Down
144 changes: 0 additions & 144 deletions bin/po2android.js

This file was deleted.

Loading