From 921f333f356dc32539ba2e4abeab1e66b53ae459 Mon Sep 17 00:00:00 2001
From: Christoph Reiter <reiter.christoph@gmail.com>
Date: Thu, 1 Jul 2021 17:55:52 +0200
Subject: [PATCH] common: add i18next-scanner support

---
 packages/common/dbp-common-demo.js              |  2 +-
 packages/common/i18next-scanner.config.js       | 17 +++++++++++++++++
 packages/common/jsonld.js                       |  2 +-
 packages/common/package.json                    |  4 +++-
 packages/common/{ => src}/i18n.js               |  2 +-
 .../common/{ => src}/i18n/de/translation.json   |  0
 .../common/{ => src}/i18n/en/translation.json   |  0
 7 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 packages/common/i18next-scanner.config.js
 rename packages/common/{ => src}/i18n.js (74%)
 rename packages/common/{ => src}/i18n/de/translation.json (100%)
 rename packages/common/{ => src}/i18n/en/translation.json (100%)

diff --git a/packages/common/dbp-common-demo.js b/packages/common/dbp-common-demo.js
index 95a9986f..9a56ef03 100644
--- a/packages/common/dbp-common-demo.js
+++ b/packages/common/dbp-common-demo.js
@@ -1,4 +1,4 @@
-import {createInstance} from './i18n.js';
+import {createInstance} from './src/i18n.js';
 import {css, html, LitElement} from 'lit-element';
 import {ScopedElementsMixin} from '@open-wc/scoped-elements';
 import * as commonUtils from './utils.js';
diff --git a/packages/common/i18next-scanner.config.js b/packages/common/i18next-scanner.config.js
new file mode 100644
index 00000000..77381926
--- /dev/null
+++ b/packages/common/i18next-scanner.config.js
@@ -0,0 +1,17 @@
+module.exports = {
+    input: [
+        'src/*.js',
+        './*.js',
+    ],
+    output: './',
+    options: {
+        debug: false,
+        removeUnusedKeys: true,
+        func: {list: ['i18n.t', '_i18n.t']},
+        lngs: ['en','de'],
+        resource: {
+            loadPath: 'src/i18n/{{lng}}/{{ns}}.json',
+            savePath: 'src/i18n/{{lng}}/{{ns}}.json'
+        },
+    },
+}
diff --git a/packages/common/jsonld.js b/packages/common/jsonld.js
index 6ce7750d..f74e38cf 100644
--- a/packages/common/jsonld.js
+++ b/packages/common/jsonld.js
@@ -1,6 +1,6 @@
 import {send as notify} from './notification';
 import * as utils from "./utils";
-import {createInstance} from "./i18n";
+import {createInstance} from "./src/i18n";
 
 export default class JSONLD {
     constructor(baseApiUrl, entities) {
diff --git a/packages/common/package.json b/packages/common/package.json
index d4ed6c5f..c14f62c5 100644
--- a/packages/common/package.json
+++ b/packages/common/package.json
@@ -25,9 +25,11 @@
     "rollup": "^2.33.3",
     "rollup-plugin-copy": "^3.1.0",
     "rollup-plugin-delete": "^2.0.0",
-    "rollup-plugin-serve": "^1.0.1"
+    "rollup-plugin-serve": "^1.0.1",
+    "i18next-scanner": "^3.0.0"
   },
   "scripts": {
+    "i18next": "i18next-scanner",
     "clean": "rm dist/*",
     "build": "rollup -c",
     "build-test": "rollup -c --environment BUILD:test",
diff --git a/packages/common/i18n.js b/packages/common/src/i18n.js
similarity index 74%
rename from packages/common/i18n.js
rename to packages/common/src/i18n.js
index 65d10ba7..ebd73472 100644
--- a/packages/common/i18n.js
+++ b/packages/common/src/i18n.js
@@ -1,4 +1,4 @@
-import {createInstance as _createInstance} from './i18next.js';
+import {createInstance as _createInstance} from '../i18next.js';
 
 import de from './i18n/de/translation.json';
 import en from './i18n/en/translation.json';
diff --git a/packages/common/i18n/de/translation.json b/packages/common/src/i18n/de/translation.json
similarity index 100%
rename from packages/common/i18n/de/translation.json
rename to packages/common/src/i18n/de/translation.json
diff --git a/packages/common/i18n/en/translation.json b/packages/common/src/i18n/en/translation.json
similarity index 100%
rename from packages/common/i18n/en/translation.json
rename to packages/common/src/i18n/en/translation.json
-- 
GitLab