Skip to content

Commit

Permalink
Merge pull request #774 from tchapgouv/translations-as-module
Browse files Browse the repository at this point in the history
Migrate translations to module
  • Loading branch information
estellecomment authored Oct 27, 2023
2 parents de4630e + cb13aee commit ed1f5e3
Show file tree
Hide file tree
Showing 15 changed files with 1,218 additions and 1,154 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ electron/pub

# Auto-generated file
/src/modules.ts
/build_config.yaml
#/build_config.yaml # :TCHAP: writes this by hand.

/cypress/videos
/cypress/downloads
Expand Down
11 changes: 11 additions & 0 deletions build_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# copied from build_config.sample.yaml
# Make sure that the modules added here are ALSO ADDED IN OPTIONALDEPENDENCIES in package.json.
modules:
# An example of pulling a module from NPM
#- "@vector-im/element-web-ilag-module@^0.0.4"

# An example of pulling a module from github
#- "github:vector-im/element-web-ilag-module#main"

# Pulling from filesystem.
- "file:./modules/tchap-translations"
2 changes: 0 additions & 2 deletions config.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@
"fdroid": null
},
"permalink_prefix": "https://www.tchap.incubateur.net",
"custom_translations_url_comments": "To add translations, edit /src/i18n/strings/tchap_translations.json. It gets copied over to webapp/i18n for serving.",
"custom_translations_url": "/i18n/tchap_translations.json",
"tchap_features": {
"feature_email_notification": [
"agent1.tchap.incubateur.net",
Expand Down
2 changes: 0 additions & 2 deletions config.preprod.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@
"fdroid": null
},
"permalink_prefix": "https://www.beta.tchap.gouv.fr",
"custom_translations_url_comments": "To add translations, edit /src/i18n/strings/tchap_translations.json. It gets copied over to webapp/i18n for serving.",
"custom_translations_url": "/i18n/tchap_translations.json",
"tchap_features": {
"feature_email_notification": ["i.tchap.gouv.fr", "e.tchap.gouv.fr"],
"feature_thread": ["i.tchap.gouv.fr", "e.tchap.gouv.fr"],
Expand Down
2 changes: 0 additions & 2 deletions config.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@
"fdroid": null
},
"permalink_prefix": "https://tchap.gouv.fr",
"custom_translations_url_comments": "To add translations, edit /src/i18n/strings/tchap_translations.json. It gets copied over to webapp/i18n for serving.",
"custom_translations_url": "/i18n/tchap_translations.json",
"tchap_features": {
"feature_email_notification": ["agent.dinum.tchap.gouv.fr"],
"feature_thread": ["agent.dinum.tchap.gouv.fr"],
Expand Down
2 changes: 0 additions & 2 deletions config.prod.lab.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@
"fdroid": null
},
"permalink_prefix": "https://tchap.gouv.fr",
"custom_translations_url_comments": "To add translations, edit /src/i18n/strings/tchap_translations.json. It gets copied over to webapp/i18n for serving.",
"custom_translations_url": "/i18n/tchap_translations.json",
"tchap_features": {
"feature_email_notification": ["agent.dinum.tchap.gouv.fr"],
"feature_thread": ["agent.dinum.tchap.gouv.fr"],
Expand Down
4 changes: 1 addition & 3 deletions config.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,5 @@
"available": false
},
"map_style_url": "https://openmaptiles.geo.data.gouv.fr/styles/osm-bright/style.json",
"permalink_prefix": "https://www.beta.tchap.gouv.fr",
"custom_translations_url_comments": "To add translations, edit /src/i18n/strings/tchap_translations.json. It gets copied over to webapp/i18n for serving.",
"custom_translations_url": "/i18n/tchap_translations.json"
"permalink_prefix": "https://www.beta.tchap.gouv.fr"
}
31 changes: 30 additions & 1 deletion module_system/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,36 @@ export function installer(config: BuildConfig): void {
try {
// Install the modules with yarn
const yarnAddRef = config.modules.join(" ");
callYarnAdd(yarnAddRef); // install them all at once
// :TCHAP: don't run the yarn install, scalingo does not like it.
// eslint-disable-next-line no-constant-condition
if (false) {
callYarnAdd(yarnAddRef); // install them all at once
}
console.log("The following modules are in build_config: ", config.modules);
// To make sure the build will work without the yarn add, check that the modules in build_config are present in optionalDependencies.
const currentOptDepsValues = Object.values(JSON.parse(packageDeps.packageJson)?.["optionalDependencies"] ?? {});
const isAllGood = config.modules.every((configLine) => {
// Check only the "file:" modules, it's too complicated to check all yarn allowed formats.
// Our modules should be "file:"
if (configLine.includes("file:")) {
if (!currentOptDepsValues.includes(configLine)) {
console.error(
"build_config.yml contains",
configLine,
"but it is not present in optionalDependencies in package.json.",
"\nYou should run : yarn add -O",
configLine,
);
return false;
}
}
return true;
});
if (!isAllGood) {
exitCode = 1;
return;
}
// end :TCHAP:

// Grab the optional dependencies again and exclude what was there already. Everything
// else must be a module, we assume.
Expand Down
13 changes: 13 additions & 0 deletions modules/tchap-translations/TchapTranslationsModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
Copyright 2023 DINUM
*/
import { RuntimeModule } from "@matrix-org/react-sdk-module-api/lib/RuntimeModule";

import tchapTranslations from "./tchap_translations.json";
export default class TchapTranslationsModule extends RuntimeModule {
constructor(moduleApi) {
super(moduleApi);

this.moduleApi.registerTranslations(tchapTranslations);
}
}
11 changes: 11 additions & 0 deletions modules/tchap-translations/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "tchap-translations",
"version": "0.0.0",
"description": "Custom translations for Tchap",
"author": "DINUM",
"license": "Apache-2.0",
"dependencies": {
"@matrix-org/react-sdk-module-api": "^1.0.0"
},
"main": "TchapTranslationsModule.js"
}
Loading

0 comments on commit ed1f5e3

Please sign in to comment.