-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1520 from wordpress-mobile/fix/i18n-gen-ios-and-a…
…ndroid-files Generate i18n files for WPAndroid and WPiOS to use
- Loading branch information
Showing
6 changed files
with
329 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env node | ||
|
||
const gettextParser = require( 'gettext-parser' ), | ||
fs = require( 'fs' ); | ||
|
||
const indent = ' '; | ||
|
||
function escapeResourceXML( unsafeXMLValue ) { | ||
// See: https://tekeye.uk/android/examples/android-string-resources-gotchas | ||
// Let's first replace XML special characters that JSON.stringify does not escape: <, > and & | ||
// Then let's use JSON.stringify to handle pre and post spaces as well as escaping ", \, \t and \n | ||
return JSON.stringify( unsafeXMLValue.replace( /[<>&]/g, function( character ) { | ||
switch ( character ) { | ||
case '<': return '<'; | ||
case '>': return '>'; | ||
case '&': return '&'; | ||
} | ||
} ) ); | ||
} | ||
|
||
function po2Android( poInput ) { | ||
const po = gettextParser.po.parse( poInput ); | ||
const translations = po.translations[ '' ]; | ||
const androidResources = Object.values( translations ).map( ( translation, id ) => { | ||
if ( translation.msgid === '' ) { | ||
return null; | ||
} | ||
const escapedValue = escapeResourceXML( translation.msgid ); | ||
const escapedValuePlural = escapeResourceXML( translation.msgid_plural || '' ); | ||
const comment = translation.comments.extracted || ''; | ||
let localizedEntry = ''; | ||
if ( comment ) { | ||
localizedEntry += `${ indent }<!-- ${ comment.replace( '--', '—' ) } -->\n`; | ||
} | ||
if ( translation.msgid_plural ) { | ||
localizedEntry += `${ indent }<plurals name="gutenberg_native_string_${ id }" tools:ignore="UnusedResources"> | ||
${ indent }${ indent }<item quantity="one">${ escapedValue }</item> | ||
${ indent }${ indent }<item quantity="other">${ escapedValuePlural }</item> | ||
${ indent }</plurals> | ||
`; | ||
} else { | ||
localizedEntry += `${ indent }<string name="gutenberg_native_string_${ id }" tools:ignore="UnusedResources">${ escapedValue }</string>\n`; | ||
} | ||
return localizedEntry; | ||
} ).filter( Boolean ); | ||
return `<?xml version="1.0" encoding="utf-8"?>\n<resources xmlns:tools="http://schemas.android.com/tools">\n${ androidResources.join( '' ) }</resources>\n`; | ||
} | ||
|
||
if ( require.main === module ) { | ||
if ( process.stdin.isTTY ) { | ||
const potFileName = process.argv[ 2 ]; | ||
const destination = process.argv[ 3 ]; | ||
const potFileContent = fs.readFileSync( potFileName ); | ||
const xmlOutput = po2Android( potFileContent, process.argv[ 3 ] ); | ||
fs.writeFileSync( destination, xmlOutput ); | ||
} else { | ||
let inputData = ''; | ||
process.stdin.on( 'readable', function() { | ||
const chunk = this.read(); | ||
if ( chunk !== null ) { | ||
inputData += chunk; | ||
} | ||
} ); | ||
process.stdin.on( 'end', function() { | ||
process.stdout.write( po2Android( inputData ) ); | ||
} ); | ||
} | ||
return; | ||
} | ||
|
||
module.exports = po2Android; | ||
|
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,43 @@ | ||
#!/usr/bin/env node | ||
|
||
const gettextParser = require( 'gettext-parser' ), | ||
fs = require( 'fs' ); | ||
|
||
function po2Swift( poInput ) { | ||
const po = gettextParser.po.parse( poInput ); | ||
const translations = po.translations[ '' ]; | ||
const swiftStrings = Object.values( translations ).map( ( translation, id ) => { | ||
if ( translation.msgid === '' ) { | ||
return null; | ||
} | ||
const encodedValue = JSON.stringify( translation.msgid ); | ||
const encodedComment = JSON.stringify( translation.comments.extracted || '' ); | ||
return `let string${ id } = NSLocalizedString(${ encodedValue }, comment: ${ encodedComment })`; | ||
} ).filter( Boolean ); | ||
return swiftStrings.join( '\n' ) + '\n'; | ||
} | ||
|
||
if ( require.main === module ) { | ||
if ( process.stdin.isTTY ) { | ||
const potFileName = process.argv[ 2 ]; | ||
const destination = process.argv[ 3 ]; | ||
const potFileContent = fs.readFileSync( potFileName ); | ||
const swiftOutput = po2Swift( potFileContent, process.argv[ 3 ] ); | ||
fs.writeFileSync( destination, swiftOutput ); | ||
} else { | ||
let inputData = ''; | ||
process.stdin.on( 'readable', function() { | ||
const chunk = this.read(); | ||
if ( chunk !== null ) { | ||
inputData += chunk; | ||
} | ||
} ); | ||
process.stdin.on( 'end', function() { | ||
process.stdout.write( po2Swift( inputData ) ); | ||
} ); | ||
} | ||
return; | ||
} | ||
|
||
module.exports = po2Swift; | ||
|
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,104 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources xmlns:tools="http://schemas.android.com/tools"> | ||
<!-- translators: accessibility text for blocks with invalid content. %d: localized block title --> | ||
<string name="gutenberg_native_string_1" tools:ignore="UnusedResources">"%s block. This block has invalid content"</string> | ||
<string name="gutenberg_native_string_2" tools:ignore="UnusedResources">"Problem displaying block"</string> | ||
<!-- translators: accessibility text. %s: current block position (number). --> | ||
<string name="gutenberg_native_string_3" tools:ignore="UnusedResources">"Remove block at row %s"</string> | ||
<string name="gutenberg_native_string_4" tools:ignore="UnusedResources">"Double tap to remove the block"</string> | ||
<!-- translators: accessibility text. %s: block name. --> | ||
<string name="gutenberg_native_string_5" tools:ignore="UnusedResources">"%s Block"</string> | ||
<string name="gutenberg_native_string_6" tools:ignore="UnusedResources">"Row %d."</string> | ||
<string name="gutenberg_native_string_7" tools:ignore="UnusedResources">"Navigate Up"</string> | ||
<string name="gutenberg_native_string_8" tools:ignore="UnusedResources">"ADD BLOCK HERE"</string> | ||
<!-- translators: accessibility text. %1: current block position (number). %2: next block position (number) --> | ||
<string name="gutenberg_native_string_9" tools:ignore="UnusedResources">"Move block up from row %1$s to row %2$s"</string> | ||
<string name="gutenberg_native_string_10" tools:ignore="UnusedResources">"Move block up"</string> | ||
<string name="gutenberg_native_string_11" tools:ignore="UnusedResources">"Double tap to move the block up"</string> | ||
<!-- translators: accessibility text. %1: current block position (number). %2: next block position (number) --> | ||
<string name="gutenberg_native_string_12" tools:ignore="UnusedResources">"Move block down from row %1$s to row %2$s"</string> | ||
<string name="gutenberg_native_string_13" tools:ignore="UnusedResources">"Move block down"</string> | ||
<string name="gutenberg_native_string_14" tools:ignore="UnusedResources">"Double tap to move the block down"</string> | ||
<string name="gutenberg_native_string_15" tools:ignore="UnusedResources">"Open Settings"</string> | ||
<string name="gutenberg_native_string_16" tools:ignore="UnusedResources">"Start writing…"</string> | ||
<string name="gutenberg_native_string_17" tools:ignore="UnusedResources">"Double tap to add a block"</string> | ||
<string name="gutenberg_native_string_18" tools:ignore="UnusedResources">"ADD IMAGE"</string> | ||
<string name="gutenberg_native_string_19" tools:ignore="UnusedResources">"ADD VIDEO"</string> | ||
<string name="gutenberg_native_string_20" tools:ignore="UnusedResources">"ADD IMAGE OR VIDEO"</string> | ||
<string name="gutenberg_native_string_21" tools:ignore="UnusedResources">"Double tap to select"</string> | ||
<string name="gutenberg_native_string_22" tools:ignore="UnusedResources">"Double tap to select an image"</string> | ||
<string name="gutenberg_native_string_23" tools:ignore="UnusedResources">"Double tap to select a video"</string> | ||
<!-- translators: accessibility text for the media block empty state. %s: media type --> | ||
<string name="gutenberg_native_string_24" tools:ignore="UnusedResources">"%s block. Empty"</string> | ||
<string name="gutenberg_native_string_25" tools:ignore="UnusedResources">"Failed to insert media.\nPlease tap for options."</string> | ||
<string name="gutenberg_native_string_26" tools:ignore="UnusedResources">"Take a Video"</string> | ||
<string name="gutenberg_native_string_27" tools:ignore="UnusedResources">"Take a Photo"</string> | ||
<string name="gutenberg_native_string_28" tools:ignore="UnusedResources">"Take a Photo or Video"</string> | ||
<string name="gutenberg_native_string_29" tools:ignore="UnusedResources">"Choose from device"</string> | ||
<string name="gutenberg_native_string_30" tools:ignore="UnusedResources">"WordPress Media Library"</string> | ||
<string name="gutenberg_native_string_31" tools:ignore="UnusedResources">"Ungroup"</string> | ||
<string name="gutenberg_native_string_32" tools:ignore="UnusedResources">"Paste URL"</string> | ||
<string name="gutenberg_native_string_33" tools:ignore="UnusedResources">"Problem opening the video"</string> | ||
<string name="gutenberg_native_string_34" tools:ignore="UnusedResources">"No application can handle this request. Please install a Web browser."</string> | ||
<string name="gutenberg_native_string_35" tools:ignore="UnusedResources">"An unknown error occurred. Please try again."</string> | ||
<!-- translators: accessibility text. %s: heading level. --> | ||
<string name="gutenberg_native_string_36" tools:ignore="UnusedResources">"Level %s. Empty."</string> | ||
<!-- translators: accessibility text. 1: heading level. 2: heading content. --> | ||
<string name="gutenberg_native_string_37" tools:ignore="UnusedResources">"Level %1$s. %2$s"</string> | ||
<string name="gutenberg_native_string_38" tools:ignore="UnusedResources">"Clear All Settings"</string> | ||
<string name="gutenberg_native_string_39" tools:ignore="UnusedResources">"Add URL"</string> | ||
<string name="gutenberg_native_string_40" tools:ignore="UnusedResources">"Size"</string> | ||
<string name="gutenberg_native_string_41" tools:ignore="UnusedResources">"Alt Text"</string> | ||
<string name="gutenberg_native_string_42" tools:ignore="UnusedResources">"Double tap and hold to edit"</string> | ||
<!-- translators: accessibility text. %s: image caption. --> | ||
<string name="gutenberg_native_string_43" tools:ignore="UnusedResources">"Image caption. %s"</string> | ||
<string name="gutenberg_native_string_44" tools:ignore="UnusedResources">"Empty"</string> | ||
<string name="gutenberg_native_string_45" tools:ignore="UnusedResources">"Unsupported"</string> | ||
<!-- translators: accessibility text. %s: Page break text. --> | ||
<string name="gutenberg_native_string_46" tools:ignore="UnusedResources">"Page break block. %s"</string> | ||
<!-- translators: accessibility text --> | ||
<string name="gutenberg_native_string_47" tools:ignore="UnusedResources">"Double tap to edit this value"</string> | ||
<string name="gutenberg_native_string_48" tools:ignore="UnusedResources">"Current value is %s"</string> | ||
<!-- translators: accessibility text (hint for focusing a slider) --> | ||
<string name="gutenberg_native_string_49" tools:ignore="UnusedResources">"Double tap to change the value using slider"</string> | ||
<!-- translators: accessibility text (hint for switches) --> | ||
<string name="gutenberg_native_string_50" tools:ignore="UnusedResources">"Double tap to toggle setting"</string> | ||
<string name="gutenberg_native_string_51" tools:ignore="UnusedResources">"Content…"</string> | ||
<string name="gutenberg_native_string_52" tools:ignore="UnusedResources">"Reset Block"</string> | ||
<string name="gutenberg_native_string_53" tools:ignore="UnusedResources">"Add a description"</string> | ||
<string name="gutenberg_native_string_54" tools:ignore="UnusedResources">"Add annotation"</string> | ||
<string name="gutenberg_native_string_55" tools:ignore="UnusedResources">"Remove annotations"</string> | ||
<string name="gutenberg_native_string_56" tools:ignore="UnusedResources">"Annotations Sidebar"</string> | ||
<string name="gutenberg_native_string_57" tools:ignore="UnusedResources">"My Document Setting Panel"</string> | ||
<string name="gutenberg_native_string_58" tools:ignore="UnusedResources">"My post status info"</string> | ||
<string name="gutenberg_native_string_59" tools:ignore="UnusedResources">"Here is the panel content!"</string> | ||
<string name="gutenberg_native_string_60" tools:ignore="UnusedResources">"My pre publish panel"</string> | ||
<string name="gutenberg_native_string_61" tools:ignore="UnusedResources">"My post publish panel"</string> | ||
<string name="gutenberg_native_string_62" tools:ignore="UnusedResources">"Title:"</string> | ||
<string name="gutenberg_native_string_63" tools:ignore="UnusedResources">"Sidebar title plugin"</string> | ||
<string name="gutenberg_native_string_64" tools:ignore="UnusedResources">"Double tap to undo last change"</string> | ||
<string name="gutenberg_native_string_65" tools:ignore="UnusedResources">"Double tap to redo last change"</string> | ||
<string name="gutenberg_native_string_66" tools:ignore="UnusedResources">"Hide keyboard"</string> | ||
<string name="gutenberg_native_string_67" tools:ignore="UnusedResources">"Tap to hide the keyboard"</string> | ||
<!-- translators: Checkbox toggle label --> | ||
<string name="gutenberg_native_string_68" tools:ignore="UnusedResources">"Show section"</string> | ||
<!-- translators: accessibility text. empty post title. --> | ||
<string name="gutenberg_native_string_69" tools:ignore="UnusedResources">"Post title. Empty"</string> | ||
<!-- translators: accessibility text. %s: text content of the post title. --> | ||
<string name="gutenberg_native_string_70" tools:ignore="UnusedResources">"Post title. %s"</string> | ||
<string name="gutenberg_native_string_71" tools:ignore="UnusedResources">"Link inserted"</string> | ||
<string name="gutenberg_native_string_72" tools:ignore="UnusedResources">"Link text"</string> | ||
<string name="gutenberg_native_string_73" tools:ignore="UnusedResources">"Add link text"</string> | ||
<string name="gutenberg_native_string_74" tools:ignore="UnusedResources">"Translate"</string> | ||
<string name="gutenberg_native_string_75" tools:ignore="UnusedResources">"hello"</string> | ||
<plurals name="gutenberg_native_string_76" tools:ignore="UnusedResources"> | ||
<item quantity="one">"%d banana"</item> | ||
<item quantity="other">"%d bananas"</item> | ||
</plurals> | ||
<string name="gutenberg_native_string_77" tools:ignore="UnusedResources">"hello %s"</string> | ||
<string name="gutenberg_native_string_78" tools:ignore="UnusedResources">"cheeseburger"</string> | ||
<plurals name="gutenberg_native_string_79" tools:ignore="UnusedResources"> | ||
<item quantity="one">"%d cat"</item> | ||
<item quantity="other">"%d cats"</item> | ||
</plurals> | ||
</resources> |
Oops, something went wrong.