Skip to content

Commit

Permalink
[RNMobile] Add GlotPress project slug parameter to translations pipel…
Browse files Browse the repository at this point in the history
…ine (#49558)

* Avoid logging deprecate PHP messages

* Add project slug parameter to translation pipeline
  • Loading branch information
fluiddot authored Apr 4, 2023
1 parent 14d944e commit b3c8bc3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
6 changes: 4 additions & 2 deletions packages/react-native-editor/bin/extract-used-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-editor/bin/generate-pot-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 19 additions & 10 deletions packages/react-native-editor/bin/i18n-translations-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand All @@ -243,6 +251,7 @@ if ( require.main === module ) {

fetchTranslations( {
plugin,
projectSlug,
pluginDir,
usedStrings,
} ).then( ( { translations, missingTranslations, extraTranslations } ) => {
Expand Down

1 comment on commit b3c8bc3

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in b3c8bc3.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4605312537
📝 Reported issues:

Please sign in to comment.