Skip to content
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

i18n + FR #1610

Merged
merged 51 commits into from
Apr 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
0e42520
add localization tags and 3 translation examples
pciavald Mar 23, 2021
79f5a25
build all locales, warn on missing translation
pciavald Mar 23, 2021
2991cd3
Version française V1.0 de la traduction
Mar 25, 2021
5f45a66
delete yarn.lock
pciavald Mar 25, 2021
42fd53a
update package.json with upstream
pciavald Mar 26, 2021
7fe0d10
re-add @angular/localize
pciavald Mar 26, 2021
d0f5b97
merge upstream
pciavald Mar 26, 2021
5a17b8d
fix merge
pciavald Mar 26, 2021
5455084
re-add extract command
pciavald Mar 26, 2021
58bfd22
add ids
pciavald Mar 26, 2021
e85b3ec
replace added spans by ng-containers
pciavald Mar 26, 2021
ff7648a
fix duplicate id
pciavald Mar 26, 2021
aca0c8b
replace spans by ng-containers
pciavald Mar 26, 2021
989c3a7
basic docs
pciavald Mar 27, 2021
50a6370
Prise en compte des review pour la traduction française V1.00
Mar 27, 2021
77fe58c
Merge branch 'i18n' of https://git.iostud.io/vs-projects/octodash int…
Mar 27, 2021
2032b28
remove irrelevant change
pciavald Mar 27, 2021
c25edcb
cleanup angular.json
pciavald Mar 27, 2021
225c7b3
fix FR translations and merge ids
pciavald Mar 27, 2021
a33ea6e
fix package-lock conflict
pciavald Mar 27, 2021
c3dcd51
revert to fr instead of fr-FR
pciavald Mar 27, 2021
165510f
revert fr-FR to fr
pciavald Mar 27, 2021
7394404
fix targets that were sources
pciavald Mar 27, 2021
e8552c8
revert out-file
pciavald Mar 27, 2021
c6673d5
revert package-lock
pciavald Mar 27, 2021
f5cb861
install angular i18n
pciavald Mar 27, 2021
e28498e
fix build issues
pciavald Mar 27, 2021
56cfc57
enable serving custom locales, build detects host lang
pciavald Mar 28, 2021
e4c400b
update command name
pciavald Mar 28, 2021
4bd4017
correct source language
pciavald Mar 28, 2021
97b8477
update locales
pciavald Mar 28, 2021
07e999e
add target language
pciavald Mar 28, 2021
e538f80
add missing semicolons
pciavald Mar 28, 2021
f9be03f
fix duplicate url setting
pciavald Mar 28, 2021
e5a3166
fix sourcelocale basehref
pciavald Mar 28, 2021
2e3105c
fix typo
pciavald Mar 28, 2021
c55ecf9
Nettoyage de coquilles de traduction fance V1.00
Mar 28, 2021
c988918
remove irrelevant files
pciavald Mar 28, 2021
4a7c8b3
Nettoyage de doublons de traduction France V1.00
Mar 29, 2021
7a97c24
Merge branch 'i18n' of https://git.iostud.io/vs-projects/octodash int…
Mar 29, 2021
15472b4
fix adjust screen
pciavald Apr 8, 2021
7e7b431
fix spacing
pciavald Apr 8, 2021
24760f4
comment fixes
pciavald Apr 9, 2021
38a2b08
Merge branch 'upstream' into i18n
pciavald Apr 9, 2021
66907de
translation adjustments
pciavald Apr 9, 2021
44991c3
please linter
pciavald Apr 9, 2021
a3de092
please linter
pciavald Apr 9, 2021
8f57b66
trailing whitespace
pciavald Apr 9, 2021
04d2608
lint autofix
pciavald Apr 9, 2021
1b49d59
use lodash and update package-lock.json
UnchartedBull Apr 11, 2021
156fd4f
revert lodash
UnchartedBull Apr 11, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

If you can think of something nice to add or want to change / extend some of the functionality, feel free to create a Pull Request or an Issue. Please make sure to follow the code style (.prettierrc is included in the GitHub) and not break any of the existing functionality. Any help is greatly appreciated!

## Setting up the repository and build the package

## Prerequisites

- NodeJS v14
Expand All @@ -17,3 +19,67 @@ To setup a local environment you need to do the following steps:
- Run the build `npm run build` (only required once to copy assets)
- Start the Live Server: `npm run start` or `npm run start:big`
- If you want to package OctoDash, so you can install it on your Raspberry Pi: `npm run pack`

## Languages

To launch the app in development mode in a specific locale instead of the source english locale, use

```
npm run start --serve="--configuration=<lang>"
```

For a list of available locales have a look at the `angular.json` (`projects.OctoDash.i18n.locales`) file.

### Add a new language

To add a language to the list of supported languages, follow these steps:

- find your language code in [this list](https://github.com/angular/angular/tree/master/packages/common/locales) (angular country codes are not all standard)
- in src/locale, duplicate an existing locale (or run `npm run locale:extract` to generate a new locale file)
- rename the file to include your language code in the format `messages.<languageCode>.xlf`
- in the `<file>` tag (second line of the xlf file) adapt `source-language="<languageCode>"` to your language code
- add the translations for your language between `target` tags
- add your language reference in `angular.json`

- `Projects.OctoDash.i18n.locales`

- add:

```
"<lang>": {
"translation": "src/locale/messages.<lang>.xlf",
"baseHref": ""
}
```

- `Projects.OctoDash.architect.build.configurations.production.localize`.

- add:

```
"<lang>"
```

- `Projects.OctoDash.architect.build.configurations`.

- add:

```
"<lang>": {
"localize": ["<lang>"]
},
```

- `Projects.OctoDash.architect.serve.configurations`.

- add:

```
"<lang>": {
"browserTarget": "OctoDash:build:<lang>"
},
```

## Update translations IDs and sources

To update translations with the latest codebase and IDs, run `npm run locale:update`. Only commit the files that do not have a date, these are only backups of the locale versions before the update.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ For more info have a look at the [wiki](https://github.com/UnchartedBull/OctoDas
- You can press multiple arrows directly after another in the control view. All actions will be executed in series, even if the prior didn't finish
- The six actions on the right in the control view can be customized. They can either send GCode commands to your printer, restart OctoPrint or your Pi and even open iFrames so you can view your camera
- You can adjust the temperatures and fan speed in the home screen by pressing on their icons, if you want to set them to zero, just tap the value once (v1.4.1 and up)
- OctoDash will start in your host's language if it is supported. You can start OctoDash in a different supported language by starting it with `LANG=fr_FR.UTF-8 octodash`. Currently supported languages are: `fr_FR.UTF-8`, english will be used if your requested language isn't available

## Demo

If you want to see OctoDash in action, here is an awesome video from Nick on [YouTube](https://youtu.be/YI_c-DY6zU4)
If you want to see OctoDash in action, here is an awesome video from Nick on [YouTube](https://youtu.be/YI_c-DY6zU4) there is also a video available from Chris Riley, which also shows the installation process on [YouTube](https://youtu.be/kwo3HMBnqC4)

## Screenshots

Expand Down Expand Up @@ -96,7 +97,7 @@ If you encounter an issue, while using OctoDash please have a look at the [wiki]

## Bugs and more

If you find a bug, please open an issue, so I can have a look at it. Please also add the steps to reproduce and the .gcode file. Thank you!
If you find a bug, please open an issue, so I can have a look at it. Please also add the steps to reproduce and the .gcode file (if applicable). Thank you!

## Contributing

Expand Down
25 changes: 22 additions & 3 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,28 @@
"root": "",
"sourceRoot": "src",
"prefix": "app",
"i18n": {
"sourceLocale": {
"code": "en",
"baseHref": ""
},
"locales": {
"fr": {
"translation": "src/locale/messages.fr.xlf",
"baseHref": ""
}
}
},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"allowedCommonJsDependencies": [
"lottie-web"
],
"allowedCommonJsDependencies": ["lottie-web"],
"aot": true,
"outputPath": "dist",
"index": "src/index.html",
"i18nMissingTranslation": "warning",
"localize": ["en"],
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
Expand All @@ -47,7 +59,11 @@
"scripts": []
},
"configurations": {
"fr": {
"localize": ["fr"]
},
"production": {
"localize": ["en", "fr"],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
Expand Down Expand Up @@ -82,6 +98,9 @@
"browserTarget": "OctoDash:build"
},
"configurations": {
"fr": {
"browserTarget": "OctoDash:build:fr"
},
UnchartedBull marked this conversation as resolved.
Show resolved Hide resolved
"production": {
"browserTarget": "OctoDash:build:production"
}
Expand Down
12 changes: 4 additions & 8 deletions helper/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ function activateScreenSleepListener(ipcMain) {
ipcMain.on('screenControl', (_, screenCommand) => exec(screenCommand.command));
}

function activateReloadListener(ipcMain, window, dev) {
function activateReloadListener(ipcMain, window, url) {
ipcMain.on('reload', () => {
if (dev) {
window.loadURL('http://localhost:4200');
} else {
window.loadURL('app://.');
}
window.loadURL(url);
});
}

Expand All @@ -44,11 +40,11 @@ function activateConfigListener(ipcMain, window) {
ipcMain.on('checkConfig', (_, config) => checkConfig(window, config));
}

function activateListeners(ipcMain, window, app, dev) {
function activateListeners(ipcMain, window, app, url) {
activateConfigListener(ipcMain, window);
activateAppInfoListener(ipcMain, window, app);
activateScreenSleepListener(ipcMain);
activateReloadListener(ipcMain, window, dev);
activateReloadListener(ipcMain, window, url);
activateUpdateListener(ipcMain, window);
activateDiscoverListener(ipcMain, window);
}
Expand Down
86 changes: 86 additions & 0 deletions helper/locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* eslint-disable @typescript-eslint/no-var-requires */

function getLocale() {
const i18n = require('../angular.json').projects.OctoDash.i18n;
let lang;
try {
// Detect if environment LANG is set
// if it is defined, convert LANG from ie 'en_US.UTF-8' to 'en-US'
// if not defined, set it to the source locale
lang = process.env['LANG'] ? process.env['LANG'].split('.')[0].replace('_', '-') : i18n.sourceLocale.code;
} catch (e) {
// LANG was populated with something else than a standard locale code
lang = i18n.sourceLocale.code;
}
// Check if exact LANG exists in our locales
const exactLocale = Object.keys(i18n.locales).includes(lang) && lang;
// Make the short version, convert ie 'en-US' to 'en'
const shortLang = lang.split('-')[0];
// This matches 'fr-CA' to 'fr' if 'fr-CA' is not defined but 'fr' is
const approximateLocale = Object.keys(i18n.locales).includes(shortLang) && shortLang;
// Define locale by either the exact, approximate, or source locale in this order
const locale = exactLocale || approximateLocale || i18n.sourceLocale.code;
console.info('selected language: ' + locale);
return locale;
}

// updates all supported locales consuming an updated messages.xlf
function updateLocales() {
const fs = require('fs');
const xliff = require('xliff');

// list all existing locales
let translatedXLFs = [];
const filenames = fs.readdirSync('./src/locale');
for (let filename of filenames) {
const match = filename.match(/messages.(..|..-..).xlf/);
if (match) {
const lang = match[1];
translatedXLFs.push({ filename, lang });
}
}

// get extracted messages
const extractedXLF = fs.readFileSync('./src/locale/messages.xlf').toString();
xliff.xliff12ToJs(extractedXLF, (err, extracted) => {
if (err) throw new Error(err.message);

// for each supported locale
for (let translatedXLFRef of translatedXLFs) {
const translatedXLF = fs.readFileSync(`./src/locale/${translatedXLFRef.filename}`).toString();

// load this locale
xliff.xliff12ToJs(translatedXLF, (err, translated) => {
if (err) throw new Error(err.message);

// hard copy of messages.xlf
const newTranslation = JSON.parse(JSON.stringify(extracted));
newTranslation.targetLanguage = translated.targetLanguage;
// transfer the locale's translations to the copy of the extracted locale
for (let id in newTranslation.resources['ng2.template']) {
const source = translated.resources['ng2.template'];
const target = newTranslation.resources['ng2.template'];
// only copy if the translation has a target
if (source[id]) {
target[id].target = source[id]?.target || '';
}
}
// backup the previous version of the locale and write the new locale
xliff.jsToXliff12(newTranslation, (err, result) => {
if (err) throw new Error(err.message);
const now = new Date();
fs.renameSync(
`./src/locale/${translatedXLFRef.filename}`,
`./src/locale/messages.${translatedXLFRef.lang}-${now.toISOString()}.xlf`,
);
console.info(`updating ${translatedXLFRef.filename}...`);
fs.writeFileSync(`./src/locale/${translatedXLFRef.filename}`, result);
});
});
}
// remove extracted messages
fs.unlinkSync('./src/locale/messages.xlf');
});
}

module.exports = { getLocale, updateLocales };
15 changes: 10 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ const dev = args.some(val => val === '--serve');

const activateListeners = require('./helper/listener');

let window;
let locale;
let url;

if (!dev) {
const createProtocol = require('./helper/protocol');
const scheme = 'app';

protocol.registerSchemesAsPrivileged([{ scheme: scheme, privileges: { standard: true } }]);
createProtocol(scheme, path.join(__dirname, 'dist'));

locale = require('./helper/locale.js').getLocale();
}

app.commandLine.appendSwitch('touch-events', 'enabled');

let window;

function createWindow() {
const _store = new Store();

Expand Down Expand Up @@ -57,14 +61,15 @@ function createWindow() {
});

if (dev) {
window.loadURL('http://localhost:4200');
url = 'http://localhost:4200';
window.webContents.openDevTools();
} else {
window.loadURL('app://.');
url = `file://${__dirname}/dist/${locale}/index.html`;
window.setFullScreen(true);
}

activateListeners(ipcMain, window, app, dev);
window.loadURL(url);
activateListeners(ipcMain, window, app, url);

window.on('closed', () => {
window = null;
Expand Down
Loading