-
Notifications
You must be signed in to change notification settings - Fork 57
Use i18n update script when generating JS bundle #4411
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
Merged
Merged
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 6e241e1
Remove makepot commands and no longer needed scripts
fluiddot 3e66063
Remove translation files of jetpack and layout-grid
fluiddot 6693dda
Use translation files from i18n-cache folder
fluiddot 5405d5d
Update localization strings files
fluiddot 109eb44
Merge branch 'add/i18n-update-script' into add/use-i18n-update-on-bundle
fluiddot b015a64
Update localization strings files
fluiddot 7d5a272
Merge branch 'add/i18n-update-script' into add/use-i18n-update-on-bundle
fluiddot 3fc857a
Update android-build-image docker image version
fluiddot 5d65aff
Add skip if cache option to i18n update script
fluiddot 3a68754
Update .gitignore
fluiddot 3c3bb03
Attach i18n update to postinstall command
fluiddot b423c75
Extract update gutenberg i18n cache to a function
fluiddot f89eb16
Fix i18n update upon dependencies install
fluiddot fb9e3f5
Update i18n cache path in CircleCI jobs
fluiddot 45422de
Update gb-mobile-image docker image version
fluiddot 9af4de6
Add i18n check cache script
fluiddot 535b7ee
Update script description
fluiddot 0832eda
Update Gutenberg ref
fluiddot 144a07d
Add WP_CLI_ALLOW_ROOT env variable to pipeline
fluiddot 9c998ce
Update gb-mobile-image version for testing
fluiddot c68a1b3
Update Gutenberg ref
fluiddot 40fa739
Use latest gb-mobile-image version
fluiddot b0c47c9
Update Gutenberg ref
fluiddot 7350438
Merge branch 'develop' into add/use-i18n-update-on-bundle
fluiddot 2f735a6
Remove wrong parameter validation
fluiddot c44a212
Remove unnecessary plugin_name parameter
fluiddot 6e81af1
Update Gutenberg ref with merge commit
fluiddot 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -120,3 +120,6 @@ bin/wp-cli.phar | |
|
|
||
| ios/Pods | ||
| ios/vendor | ||
|
|
||
| # i18n update | ||
| i18n-test/ | ||
This file contains hidden or 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,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" |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -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" | ||
|
Contributor
Author
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 removed the |
||
| 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 | ||
| ;; | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
| } | ||
|
|
||
|
|
@@ -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 | ||
|
|
@@ -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]} | ||
|
|
||
|
|
||
This file was deleted.
Oops, something went wrong.
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.
This is a test folder we could use when testing the i18n update command.