Skip to content

Commit

Permalink
Progress on new localization stuff:
Browse files Browse the repository at this point in the history
- Added python scripts for calling the python scripts from the mac-mouse-fix repo. (The mmf repo is expected to be at ./../mac-mouse-fix).
- Now calling new preprocess.py script before compiling, which calls python script inside the mac-mouse-fix repo which compiles ./locales/Localizble.xcstrings file to ./locales/Localizable.js file.
- Localizable.js is now where nuxt loads translated strings from.
- Also some improves docs and minor stuff.

- This stuff still needs a bit of work but I need a break.

TODO:
- Make quote-strings display properly in their sourceLanguage (mostly English)
- Load language name and flag using python script instead of hardcoding
- Show full list of languages in the language picker (even if they are 0% localized)
- Show a 'translation progress' message at the top if a language is not 100% localized. (Similar to what we do for markdown files)

After that:
- Make the upload-strings script upload the website strings as well.
	(We'll probably have to hack the .pbxproject file to make that smooth, but in a simple way)
- (PERHAPS) Implement a sync-strings script for syncing the mmf-website source files with the Localizble.xcstrings file.
	(This is probably not that necessary.)
  • Loading branch information
noah-nuebling committed Jun 30, 2024
1 parent a3c7519 commit bf50705
Show file tree
Hide file tree
Showing 8 changed files with 405 additions and 11 deletions.
12 changes: 8 additions & 4 deletions i18n.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ Note: Since there are so few options here it would be better to put this into nu
should be possible. But when I try it doesn't compile for some reason.
*/

import Localizable from "./locales/Localizable"

export default defineI18nConfig(() => ({

legacy: false,
fallbackLocale: 'en-US',
fallbackLocale: 'en',
fallbackWarn: false, // Consider enabling for translators after debugging, where these are annoying Edit: it still warns about missing keys, so this option is kinda pointless...



warnHtmlMessage: false, // Allow HTML in localization files (doesn't work)
warnHtmlInMessage: 'off'
warnHtmlInMessage: 'off',

messages: Localizable['strings']

}))
5 changes: 4 additions & 1 deletion locales/LocalesReadme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## On automatic analysis

(Outdated)
(Since we don't use the autoanalysis script anymore and instead use .xcstrings now.)

The python script in the MMF repo which automatically analyzes missing, superfluous and outdated translations, relies on the file structure here to be like:

Base file at:
Expand All @@ -19,7 +22,7 @@ The only purpose is so that we use the `xcodebuild` command-line-tool to export

I'm not entirelyyy sure the Xcode project is necessary.

We had to add the `dummy-xcode-target` Target (it's a macOS `App` target. I also tried more lightweight targets like a Command Line Tool but it didn't work), in order for the "Export Localizations..." option in Xcode to work. Not sure if this is also necessary for exporting .xcloc files using the `xcodebuild` command-line-tool which we plan to use.
We had to add the `dummy-xcode-target` Target, and then add the .xcstrings file to that target. (It's a macOS `App` target. I also tried more lightweight targets like a Command Line Tool but it didn't work), in order for the "Export Localizations..." option in Xcode to work. Not sure if this is also necessary for exporting .xcloc files using the `xcodebuild` command-line-tool which we plan to use.
Sidenote: After creating the target in the Xcode Project, we had to turn off the "Generate Info.plist File" build setting and turn off localization for MainMenu.xib to prevent those files from adding unnecessary strings to the .xcloc exports.

To export an .xcloc file for German into the folder `localization-export` go to the folder that contains the .xcodeproj file and use the following command:
Expand Down
312 changes: 312 additions & 0 deletions locales/Localizable.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ export default defineNuxtConfig({
configPath: '~~/tailwind.config.js'
},
i18n: {
langDir: './locales/',
langDir: null, //'./locales/',
locales: [
// Note for translators: When you add your language here, you'll have to choose a language ID for your language such as `en-US` for American English or `de` for German.
// Choose the same language ID that's used in the MMF Xcode project or find a language ID using this Apple documentation: https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPInternational/LanguageandLocaleIDs/LanguageandLocaleIDs.html
{ code: 'en-US', iso: 'en-US', name: '🇬🇧 English', file: 'en-US.js', dir: 'ltr' },
{ code: 'de', iso: 'de', name: '🇩🇪 Deutsch', file: 'de.js', dir: 'ltr' },
{ code: 'en', iso: 'en', name: '🇬🇧 English', dir: 'ltr' },
{ code: 'de', iso: 'de', name: '🇩🇪 Deutsch', dir: 'ltr' },
],
defaultLocale: 'en-US',
defaultLocale: 'en',
vueI18n: './i18n.config.ts',
compilation: {
strictMessage: false, // Allow HTML in localization files.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
],
"scripts": {
"upload": "./scripts/deploy.sh",
"generate": "node ./scripts/copy-licenseinfo.cjs && nuxt generate",
"dev": "node ./scripts/copy-licenseinfo.cjs && nuxt dev"
"generate": "python3 ./scripts/preprocess.py && nuxt generate",
"dev": "python3 ./scripts/preprocess.py && nuxt dev"
},
"devDependencies": {
"@nuxt/devtools": "latest",
Expand Down
3 changes: 3 additions & 0 deletions scripts/copy-licenseinfo.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
// - 2. Using vite-plugin-static-copy to copy from assets to public -> Doesn't seem to work with SSG. See https://github.com/sapphi-red/vite-plugin-static-copy/discussions/68
// - 3. Using nuxt3's useFetch() to access public folder from vue components -> Is buggy. With possible workarounds. See https://github.com/nuxt/nuxt/issues/13857.
// - 4. Using custom server routing to make licenseconfig appear at the server root -> This might work well. I didn't test it. See https://github.com/nuxt/nuxt/issues/15779
//
// Note: .cjs instead of .js file ext is necessary to makre require() work (not sure why) (Update, you can use .mjs to make import work)

// Imports
const fs = require('fs');
const path = require('path');

Expand Down
25 changes: 25 additions & 0 deletions scripts/preprocess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
This script is run before compiling the project.
Note:
- We used to have this be in javascript (.mjs) but that didn't print the prints of the scripts it invoked? I'm just more familiar with python.
"""


import subprocess

def main():

# Compile .xcstrings to .js
print("Calling mmf-website-compile-strings script ...")
subprocess.run('python3 ./scripts/run.py mmf-website-compile-strings --output_path locales/Localizable.js', text=True, shell=True)

# Move licenseinfo to ./public folder
print("Calling copy-licenseinfo script ...")
subprocess.run('node ./scripts/copy-licenseinfo.cjs', text=True, shell=True)


if __name__ == '__main__':
main()
47 changes: 47 additions & 0 deletions scripts/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

"""
This script lets us use the python scripts that are in the mac-mouse-fix repo.
(The mac-mouse-fix repo is expected to be at ./../mac-mouse-fix/ relative to this repo.)
This lets us tap into all the nice python utility functions which we already wrote inside the mac-mouse-fix repo.
We might also write .py scripts specifically for this website, but still put them into the mac-mouse-fix repo.
"""

#
# Imports
#

# Note: Only import stdlib stuff (not pip packages) to keep this script portable and dependency-free.

import subprocess
import os
import sys

#
# Constants
#

mmf_repo_path = '../mac-mouse-fix/'
mmf_repo_run_subpath = './Scripts/run.py'
mmf_to_website_repo_path = '../mac-mouse-fix-website/'

#
# main
#
def main():

# Prepare args
args = sys.argv[1:]
args += ['--target_repo', mmf_to_website_repo_path]

# Change workding dir
os.chdir(mmf_repo_path)

# Call run.py
subprocess.run(['python3', mmf_repo_run_subpath, *args]) # Idk whether to use subprocess.run or .check_call, or something else, and whether to handle the return here

#
# Call main
#
if __name__ == '__main__':
main()

0 comments on commit bf50705

Please sign in to comment.