-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/wordpress-mobile/gutenbe…
…rg-mobile into issue/609-Show-Title-block-when-HTML-mode * 'develop' of https://github.com/wordpress-mobile/gutenberg-mobile: (44 commits) Updated bundles Add border on Title when focused (#622) Default to the device language for the example app Updates the gutenberg submodule ref. Updates the gutenberg submodule reference. Re-add rootTagsToEliminate option to RichText (#636) Give priority to the parent app translations Remove unnecessary import Fix lint issue Fallback to a locale without a regional code if not supported Add Greek support PR got merged upstream so, use upstream Run yarn i18n-cache on postinstall Run yarn prebundle before bundle:android and bundle:ios instead Use a forked+patched jsdom-jscore with normalization fix Revert "Update GB ref with fix for node.rel" Upload media progress bar is missing while media is uploading new (#631) Remove JS handling of title focus Update GB ref with fix for node.rel Update iOS translation values as arrays ...
- Loading branch information
Showing
22 changed files
with
1,349 additions
and
993 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -93,3 +93,5 @@ buck-out/ | |
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
|
||
*.pot |
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,3 @@ | ||
# ignore native version of this module as it will be generated | ||
|
||
index.native.js |
This file contains 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,3 @@ | ||
# ignore all the contents of this folder except this file | ||
* | ||
!.gitignore |
This file contains 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,129 @@ | ||
/* eslint-disable no-console */ | ||
|
||
// External dependencies | ||
const fs = require( 'fs' ); | ||
const path = require( 'path' ); | ||
const fetch = require( 'node-fetch' ); | ||
|
||
const supportedLocales = [ | ||
'ar', // Arabic | ||
'bg', // Bulgarian | ||
'cs', // Czech | ||
'cy', // Welsh | ||
'da', // Danish | ||
'de', // German | ||
'en-au', // English (Australia) | ||
'en-ca', // English (Canada) | ||
'en-gb', // English (UK) | ||
'el', // Greek | ||
'es', // Spanish | ||
'fr', // French | ||
'he', // Hebrew | ||
'hr', // Croatian | ||
'hu', // Hungarian | ||
'id', // Indonesian | ||
'is', // Icelandic | ||
'it', // Italian | ||
'ja', // Japanese | ||
'ko', // Korean | ||
'nb', // Norwegian (Bokmål) | ||
'nl', // Dutch | ||
'pl', // Polish | ||
'pt', // Portuguese | ||
'pt-br', // Portuguese (Brazil) | ||
'ro', // Romainian | ||
'ru', // Russian | ||
'sk', // Slovak | ||
'sq', // Albanian | ||
'sv', // Swedish | ||
'th', // Thai | ||
'tr', // Turkish | ||
'zh-cn', // Chinese (China) | ||
'zh-tw', // Chinese (Taiwan) | ||
]; | ||
|
||
const getLanguageUrl = ( locale ) => `https://widgets.wp.com/languages/gutenberg/${ locale }.json`; | ||
const getTranslationFilePath = ( locale ) => `./data/${ locale }.json`; | ||
|
||
const getTranslation = ( locale ) => require( getTranslationFilePath( locale ) ); | ||
|
||
const fetchTranslation = ( locale ) => { | ||
if ( ! process.env.REFRESH_I18N_CACHE ) { | ||
try { | ||
const localData = getTranslation( locale ); | ||
console.log( `Using cached locale data for ${ locale }` ); | ||
return Promise.resolve( { response: localData, locale, inCache: true } ); | ||
} catch ( error ) { | ||
// translation not found, let's fetch it | ||
} | ||
} | ||
|
||
console.log( 'fetching', getLanguageUrl( locale ) ); | ||
const localeUrl = getLanguageUrl( locale ); | ||
return fetch( localeUrl ).then( ( response ) => response.json() ).then( ( body ) => { | ||
return { response: body, locale }; | ||
} ).catch( () => { | ||
console.error( `Could not find translation file ${ localeUrl }` ); | ||
} ); | ||
}; | ||
|
||
const fetchTranslations = () => { | ||
const fetchPromises = supportedLocales.map( ( locale ) => fetchTranslation( locale ) ); | ||
|
||
return Promise.all( fetchPromises ).then( ( results ) => { | ||
const fetchedTranslations = results.filter( Boolean ); | ||
const translationFilePromises = fetchedTranslations.map( ( languageResult ) => { | ||
return new Promise( ( resolve, reject ) => { | ||
const translationRelativePath = getTranslationFilePath( languageResult.locale ); | ||
const translationAbsolutePath = path.resolve( __dirname, translationRelativePath ); | ||
|
||
if ( languageResult.inCache ) { | ||
languageResult.path = translationRelativePath; | ||
resolve( translationRelativePath ); | ||
return; | ||
} | ||
|
||
fs.writeFile( translationAbsolutePath, JSON.stringify( languageResult.response ), 'utf8', ( err ) => { | ||
if ( err ) { | ||
reject( err ); | ||
} else { | ||
languageResult.path = translationRelativePath; | ||
resolve( translationRelativePath ); | ||
} | ||
} ); | ||
} ); | ||
} ); | ||
return Promise.all( translationFilePromises ).then( () => fetchedTranslations ); | ||
} ); | ||
}; | ||
|
||
module.exports = { | ||
getTranslation, | ||
}; | ||
|
||
// if run as a script | ||
if ( require.main === module ) { | ||
fetchTranslations().then( ( translations ) => { | ||
const indexNative = `/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */ | ||
/* eslint-disable */ | ||
const translations = { | ||
${ | ||
translations.filter( Boolean ).map( ( translation ) => ( | ||
`\t"${ translation.locale }": require( "${ translation.path }" ),` | ||
) ).join( '\n' ) | ||
} | ||
}; | ||
export const getTranslation = ( locale ) => translations[ locale ]; | ||
`; | ||
|
||
fs.writeFile( path.join( __dirname, 'index.native.js' ), indexNative, 'utf8', ( error ) => { | ||
if ( error ) { | ||
console.error( error ); | ||
return; | ||
} | ||
console.log( 'Done.' ); | ||
} ); | ||
} ); | ||
} |
This file contains 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 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 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 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 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 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
Oops, something went wrong.