From e7b06ab5099265618177ef67f61034e2ee00c159 Mon Sep 17 00:00:00 2001
From: Bat <baptiste@gelez.xyz>
Date: Sun, 8 Apr 2018 17:38:26 +0100
Subject: [PATCH] i18n: .po compilation

---
 front/build/i18n.js               | 31 +++++++++++++++++++++++++++++++
 front/package.json                |  1 +
 front/static/translations/en.json |  1 +
 front/static/translations/fr.json |  1 +
 po/en.po                          | 13 +++++++++++++
 po/fr.po                          | 13 +++++++++++++
 6 files changed, 60 insertions(+)
 create mode 100644 front/build/i18n.js
 create mode 100644 front/static/translations/en.json
 create mode 100644 front/static/translations/fr.json
 create mode 100644 po/en.po
 create mode 100644 po/fr.po

diff --git a/front/build/i18n.js b/front/build/i18n.js
new file mode 100644
index 00000000..d568ee0e
--- /dev/null
+++ b/front/build/i18n.js
@@ -0,0 +1,31 @@
+const fs = require('fs');
+const path = require('path');
+const { gettextToI18next } = require('i18next-conv');
+
+// Convert .po files to i18next files
+fs.readdir(path.join(__dirname, '..', '..', 'po'), (err, files) => {
+    if (err) {
+        return console.log(err)
+    }
+
+    for (const file of files) {
+        if (file.endsWith('.po')) {
+            const lang = file.replace(/\.po$/, '')
+            const output = path.join(__dirname, '..', 'static', 'translations', `${lang}.json`)
+            fs.readFile(path.join(__dirname, '..', '..', 'po', file), (err, content) => {
+                if (err) {
+                    return console.log(err)
+                }
+
+                gettextToI18next(lang, content).then(res => {
+                    fs.writeFile(output, res, err => {
+                        if (err) {
+                            console.log(err)
+                        }
+                    })
+                })
+            })
+        }
+    }
+})
+
diff --git a/front/package.json b/front/package.json
index d67375f7..505254dc 100644
--- a/front/package.json
+++ b/front/package.json
@@ -70,6 +70,7 @@
     "friendly-errors-webpack-plugin": "^1.1.3",
     "html-webpack-plugin": "^2.28.0",
     "http-proxy-middleware": "^0.17.3",
+    "i18next-conv": "^6.0.0",
     "inject-loader": "^3.0.0",
     "karma": "^1.4.1",
     "karma-coverage": "^1.1.1",
diff --git a/front/static/translations/en.json b/front/static/translations/en.json
new file mode 100644
index 00000000..9e26dfee
--- /dev/null
+++ b/front/static/translations/en.json
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/front/static/translations/fr.json b/front/static/translations/fr.json
new file mode 100644
index 00000000..9e26dfee
--- /dev/null
+++ b/front/static/translations/fr.json
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/po/en.po b/po/en.po
new file mode 100644
index 00000000..32fbd173
--- /dev/null
+++ b/po/en.po
@@ -0,0 +1,13 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: Funkwhale 0.8\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2018-03-23 15:49-0700\n"
+"PO-Revision-Date: 2018-04-08 16:58+0100\n"
+"Last-Translator: baptiste <baptiste@gelez.xyz>\n"
+"Language-Team: English\n"
+"Language: en\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
diff --git a/po/fr.po b/po/fr.po
new file mode 100644
index 00000000..3dbbce54
--- /dev/null
+++ b/po/fr.po
@@ -0,0 +1,13 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: Funkwhale 0.8\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2018-03-23 15:49-0700\n"
+"PO-Revision-Date: 2018-04-08 16:58+0100\n"
+"Last-Translator: baptiste <baptiste@gelez.xyz>\n"
+"Language-Team: French\n"
+"Language: fr\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
-- 
GitLab