From b3c8bc37ffb9eeb5c09c1219651b346f3d5ff792 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Tue, 4 Apr 2023 09:51:19 +0200 Subject: [PATCH] [RNMobile] Add GlotPress project slug parameter to translations pipeline (#49558) * Avoid logging deprecate PHP messages * Add project slug parameter to translation pipeline --- .../bin/extract-used-strings.js | 6 ++-- .../bin/generate-pot-files.sh | 2 +- .../bin/i18n-translations-download.js | 29 ++++++++++++------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/packages/react-native-editor/bin/extract-used-strings.js b/packages/react-native-editor/bin/extract-used-strings.js index c489668c8f035a..798cda36f7a4ba 100755 --- a/packages/react-native-editor/bin/extract-used-strings.js +++ b/packages/react-native-editor/bin/extract-used-strings.js @@ -155,11 +155,13 @@ if ( require.main === module ) { const domains = [ 'gutenberg' ]; const otherPluginArgs = process.argv.slice( 3 ); const otherPlugins = []; - for ( let index = 0; index < otherPluginArgs.length; index += 2 ) { + for ( let index = 0; index < otherPluginArgs.length; index += 3 ) { const pluginName = otherPluginArgs[ index ]; - const pluginPath = path.resolve( otherPluginArgs[ index + 1 ] ); + const projectSlug = otherPluginArgs[ index + 1 ]; + const pluginPath = path.resolve( otherPluginArgs[ index + 2 ] ); otherPlugins.push( { name: pluginName, + projectSlug, sourcePath: pluginPath, } ); domains.push( pluginName ); diff --git a/packages/react-native-editor/bin/generate-pot-files.sh b/packages/react-native-editor/bin/generate-pot-files.sh index ac095d1442ed5f..5f00ca664d600c 100755 --- a/packages/react-native-editor/bin/generate-pot-files.sh +++ b/packages/react-native-editor/bin/generate-pot-files.sh @@ -191,7 +191,7 @@ fi # Define constants SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) GUTENBERG_SOURCE_CODE_DIR="$SCRIPT_DIR/../../.." -WP_CLI="php -d memory_limit=4G $SCRIPT_DIR/wp-cli.phar" +WP_CLI="php -d memory_limit=4G -d error_reporting=E_ALL&~E_DEPRECATED $SCRIPT_DIR/wp-cli.phar" BUNDLE_CLI="$GUTENBERG_SOURCE_CODE_DIR/node_modules/.bin/react-native bundle --config ${METRO_CONFIG:-metro.config.js}" # Set target path diff --git a/packages/react-native-editor/bin/i18n-translations-download.js b/packages/react-native-editor/bin/i18n-translations-download.js index 85d2f1b14e765a..714c7c0d99f8ca 100644 --- a/packages/react-native-editor/bin/i18n-translations-download.js +++ b/packages/react-native-editor/bin/i18n-translations-download.js @@ -60,31 +60,38 @@ const supportedLocales = [ 'zh-tw', // Chinese (Taiwan) ]; -const getLanguageUrl = ( locale, plugin ) => - `https://translate.wordpress.org/projects/wp-plugins/${ plugin }/dev/${ locale }/default/export-translations\?format\=json`; +const getLanguageUrl = ( locale, projectSlug ) => + `https://translate.wordpress.org/projects/${ projectSlug }/dev/${ locale }/default/export-translations\?format\=json`; const getTranslationFilePath = ( locale ) => `./data/${ locale }.json`; -const fetchTranslation = ( locale, plugin ) => { - const localeUrl = getLanguageUrl( locale, plugin ); +const fetchTranslation = ( locale, projectSlug ) => { + const localeUrl = getLanguageUrl( locale, projectSlug ); return fetch( localeUrl ) .then( ( response ) => response.json() ) .then( ( body ) => { return { response: body, locale }; } ) .catch( () => { - console.error( `Could not find translation file ${ localeUrl }` ); + console.error( + `Could not find translation file ${ localeUrl } for project slug ${ projectSlug }` + ); } ); }; -const fetchTranslations = ( { plugin, pluginDir, usedStrings } ) => { +const fetchTranslations = ( { + plugin, + projectSlug, + pluginDir, + usedStrings, +} ) => { console.log( - `Fetching translations of plugin "${ plugin }" for the following locales:`, + `Fetching translations of plugin "${ plugin }" with project slug "${ projectSlug }" for the following locales:`, supportedLocales ); const fetchPromises = supportedLocales.map( ( locale ) => - fetchTranslation( locale, plugin ) + fetchTranslation( locale, projectSlug ) ); // Create data folder if it doesn't exist @@ -230,8 +237,9 @@ const generateIndexFile = ( translations, pluginDir ) => { if ( require.main === module ) { const args = process.argv.slice( 2 ); const plugin = args[ 0 ] || 'gutenberg'; - const destination = args[ 1 ] || './i18n-cache'; - const usedStringsFile = args[ 2 ]; + const projectSlug = args[ 1 ] || 'wp-plugins/gutenberg'; + const destination = args[ 2 ] || './i18n-cache'; + const usedStringsFile = args[ 3 ]; const translationsDir = path.resolve( destination ); const pluginDir = path.join( translationsDir, plugin ); @@ -243,6 +251,7 @@ if ( require.main === module ) { fetchTranslations( { plugin, + projectSlug, pluginDir, usedStrings, } ).then( ( { translations, missingTranslations, extraTranslations } ) => {