-
diff --git a/lib/utils/i18n.js b/lib/utils/i18n.js
index 0cc8bc9b..677edf05 100644
--- a/lib/utils/i18n.js
+++ b/lib/utils/i18n.js
@@ -20,15 +20,17 @@ export const languages = {
};
export const labels = transformStructFirstSpec(label_translations_file);
-const withNamespace = (namespace) =>
- (obj) => Object.entries(obj).reduce(
+const withNamespace = (namespace) => (obj) =>
+ Object.entries(obj).reduce(
(acc, [lang, translation]) => ({
- ...Object.assign(acc, {
- [lang]: {
- [namespace]: translation
- }
- })
- }), {});
+ ...Object.assign(acc, {
+ [lang]: {
+ [namespace]: translation,
+ },
+ }),
+ }),
+ {}
+ );
console.log(withNamespace('translation')(labels));
@@ -52,7 +54,7 @@ export function initI18n(langChangeCallback = () => {}) {
{
debug: true,
fallbackLng: 'en',
- resources: withNamespace('translation')(labels), // initial resources
+ resources: withNamespace('translation')(labels), // initial resources
interpolation: {
escapeValue: false,
},
@@ -219,5 +221,4 @@ function transformStructFirstSpec(obj) {
// // ... other languages
// };
-
export { transformLangFirstSpec, transformStructFirstSpec };
diff --git a/web/index.js b/web/index.js
index f3a4cced..8124c35a 100644
--- a/web/index.js
+++ b/web/index.js
@@ -43,7 +43,6 @@ document.addEventListener('DOMContentLoaded', function () {
releasesURL: 'https://github.com/cidgoh/pathogen-genomics-package/releases',
// TODO: reduce duplication of the Template.create(); object
getLanguages: async (schema) => {
-
// Consolidate function for reducing objects
function consolidate(iterable, reducer) {
return Object.entries(iterable).reduce(reducer, {});
@@ -57,54 +56,70 @@ document.addEventListener('DOMContentLoaded', function () {
const locales = {
default: defaultLocale,
};
-
+
template.locales.forEach((locale) => {
const langcode = locale.split('-')[0];
- const nativeName = tags.language(langcode).data.record.Description[0] || 'Default';
+ const nativeName =
+ tags.language(langcode).data.record.Description[0] || 'Default';
locales[langcode] = { langcode, nativeName };
});
-
- Object.entries(template.translations).forEach(([langcode, translation]) => {
- const schema_resource = consolidate(translation.schema.slots, (acc, [slot_symbol, { name }]) => ({
- ...acc,
- [slot_symbol.replace(/ /g, '_')]: name,
- }));
-
- const enum_resource = consolidate(translation.schema.enums, (acc, [enum_symbol, { permissible_values }]) => {
- for (const [enum_value, { text }] of Object.entries(permissible_values)) {
- acc[enum_value] = text;
- }
- return acc;
- });
-
- const translated_sections = consolidate(
- translation.schema.classes[template.default.schema.name].slot_usage,
- (acc, [translation_slot_name, { slot_group }]) => ({
- ...acc,
- [translation_slot_name]: slot_group,
- })
- );
-
- const default_sections = consolidate(
- template.default.schema.classes[template.default.schema.name].slot_usage,
- (acc, [default_slot_name, { slot_group }]) => ({
- ...acc,
- [default_slot_name]: slot_group,
- })
- );
-
- const section_resource = consolidate(translated_sections, (acc, [translation_slot_name]) => ({
- ...acc,
- [default_sections[translation_slot_name]]: translated_sections[translation_slot_name],
- }));
-
- i18n.addResources(langcode.split('-')[0], 'translation', {
- ...section_resource,
- ...schema_resource,
- ...enum_resource,
- });
- });
-
+
+ Object.entries(template.translations).forEach(
+ ([langcode, translation]) => {
+ const schema_resource = consolidate(
+ translation.schema.slots,
+ (acc, [slot_symbol, { name }]) => ({
+ ...acc,
+ [slot_symbol.replace(/ /g, '_')]: name,
+ })
+ );
+
+ const enum_resource = consolidate(
+ translation.schema.enums,
+ (acc, [enum_symbol, { permissible_values }]) => {
+ for (const [enum_value, { text }] of Object.entries(
+ permissible_values
+ )) {
+ acc[enum_value] = text;
+ }
+ return acc;
+ }
+ );
+
+ const translated_sections = consolidate(
+ translation.schema.classes[template.default.schema.name].slot_usage,
+ (acc, [translation_slot_name, { slot_group }]) => ({
+ ...acc,
+ [translation_slot_name]: slot_group,
+ })
+ );
+
+ const default_sections = consolidate(
+ template.default.schema.classes[template.default.schema.name]
+ .slot_usage,
+ (acc, [default_slot_name, { slot_group }]) => ({
+ ...acc,
+ [default_slot_name]: slot_group,
+ })
+ );
+
+ const section_resource = consolidate(
+ translated_sections,
+ (acc, [translation_slot_name]) => ({
+ ...acc,
+ [default_sections[translation_slot_name]]:
+ translated_sections[translation_slot_name],
+ })
+ );
+
+ i18n.addResources(langcode.split('-')[0], 'translation', {
+ ...section_resource,
+ ...schema_resource,
+ ...enum_resource,
+ });
+ }
+ );
+
return locales;
},
getSchema: async (schema) => {
diff --git a/web/translations/translations.json b/web/translations/translations.json
index cf36e0b0..e4b1c450 100644
--- a/web/translations/translations.json
+++ b/web/translations/translations.json
@@ -1,27 +1,27 @@
{
- "open-dropdown-item": {
- "fr": "Ouvrir"
- },
- "upload-template-dropdown-item": {},
- "select-template-modal-button": {},
- "new-dropdown-item": {},
- "open-file-input": {},
- "save-as-dropdown-item": {},
- "export-to-dropdown-item": {},
- "show-all-cols-dropdown-item": {},
- "show-required-cols-dropdown-item": {},
- "show-all-rows-dropdown-item": {},
- "show-valid-rows-dropdown-item": {},
- "show-invalid-rows-dropdown-item": {},
- "jump-to-dropdown-item": {},
- "fill-dropdown-item": {},
- "validate-btn": {},
- "save-as-modal": {},
- "export-to-modal-btn": {},
- "export-to-confirm-btn": {},
- "jump-to-input": {},
- "fill-column-input": {},
- "help_release": {},
- "template_name_display": {},
- "getting-started-modal-menu": {}
+ "open-dropdown-item": {
+ "fr": "Ouvrir"
+ },
+ "upload-template-dropdown-item": {},
+ "select-template-modal-button": {},
+ "new-dropdown-item": {},
+ "open-file-input": {},
+ "save-as-dropdown-item": {},
+ "export-to-dropdown-item": {},
+ "show-all-cols-dropdown-item": {},
+ "show-required-cols-dropdown-item": {},
+ "show-all-rows-dropdown-item": {},
+ "show-valid-rows-dropdown-item": {},
+ "show-invalid-rows-dropdown-item": {},
+ "jump-to-dropdown-item": {},
+ "fill-dropdown-item": {},
+ "validate-btn": {},
+ "save-as-modal": {},
+ "export-to-modal-btn": {},
+ "export-to-confirm-btn": {},
+ "jump-to-input": {},
+ "fill-column-input": {},
+ "help_release": {},
+ "template_name_display": {},
+ "getting-started-modal-menu": {}
}