-
Notifications
You must be signed in to change notification settings - Fork 58
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
Generate i18n files for WPAndroid and WPiOS to use #1520
Conversation
These scripts stopped working because the gutenberg project changed to only obtain translations from files in the build folder after the project was built. As a result, gutenberg is not getting translations for any *.native.js files. This addresses that by: 1. Performing a gutenberg build and obtaining a pot file from `gutenberg/build/`. 2. Generating a gutenberg-mobile pot file based on the contents of `./src/*.js` and `./gutenberg/*.native.js`, while also excluding anything already contained in the gutenberg pot file that was generated in step 1.
👋 I know this is still WIP so, feel free to ignore this question: |
Hi @hypest, thanks for having a look! |
let string77 = NSLocalizedString("hello %s", comment: "") | ||
let string78 = NSLocalizedString("cheeseburger", comment: "") | ||
let string79 = NSLocalizedString("%d cat", comment: "") | ||
let string79Plural = NSLocalizedString("%d cats", comment: "") |
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.
Is there a way to have those grouped so glotpress knows string79Plural
is the plural version of string79
? Not sure who to ping to answer this 🤔 Any idea @hypest ?
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.
We don't have support for plurals yet 😞 wordpress-mobile/WordPress-iOS#6327
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.
I see. So I guess it's not worth sending those as extra strings for translations as they won't be picked up by glotpress as the plural version of other strings 🤔 Yeah in that case we should probably remove those
bin/po2android.js
Outdated
const potFileName = process.argv[ 2 ]; | ||
const destination = process.argv[ 3 ]; | ||
const potFileContent = fs.readFileSync( potFileName ); | ||
const swiftOutput = po2Android( potFileContent, process.argv[ 3 ] ); |
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.
Perhaps something like "xmlOutput" here instead 😄
@@ -68,7 +68,7 @@ | |||
"prebundle": "yarn i18n-cache:force", | |||
"prebundle:android": "yarn patch-metro-no-file-watch", | |||
"postbundle:android": "yarn un-patch-metro-no-file-watch", | |||
"bundle": "yarn bundle:android && yarn bundle:ios", | |||
"bundle": "yarn bundle:android && yarn bundle:ios && yarn clean:pot && yarn genstrings", |
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.
If there is no "gutenberg*.pot" file, then yarn clean:pot
will fail and prevent yarn genstrings
from executing. I think adding the -f
flag to the rm
command in yarn clean:pot
would be one way to fix this.
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.
Weird it's not failing for me when there is no pot file, I think this might be because of the wildcard?
I can add -f
if it fixes it for you 👍
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.
Maybe worth moving this to prebundle
with the rest of the i18n work
With these changes running Of course, this probably won't be an issue once we move to the monorepo. |
Thank you for reviewing @mchowning |
const potFileContent = fs.readFileSync( potFileName ); | ||
const swiftOutput = po2Swift( potFileContent, process.argv[ 3 ] ); | ||
fs.writeFileSync( destination, swiftOutput ); | ||
} else { |
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.
Can you explain what the non-TTY variant is for? I'm not that familiar with node on the cli, and I don't understand why there are two variants
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 so the script can work with pipes: cat gutenberg.pot | node bin/po2swift.js
.
I started with this approach because it was easier to test, and I wasn't sure which one I was going to use in package.json. It's not needed anymore so we could remove it but I figured it would be a nice addition
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.
I think this looks good. I'd be careful to avoid plurals in native JS files, since I don't think those will work on iOS yet wordpress-mobile/WordPress-iOS#6327
@koke thanks for reviewing :) |
Fixes #939
This PR adds 2 scripts to generate translation files for Wordpress-Android (as a
strings.xml
file) and WordPress-iOS (as a .swift file containing static strings). Those files will be generated and committed in thebundle
folder as:bundle/android/strings.xml
for androidbundle/ios/GutenbergNativeTranslations.swift
for iOSThis process will require a script on each app repository so those 2 files are read and included in the glotpress input file and thus the gutenberg mobile translations will be available in glotpress:
Note that only the strings that are in
.(native|ios|android).js
files are considered and those that are already part of gutenberg glotpress project (web) are excluded as well.