about summary refs log tree commit diff
path: root/config
diff options
context:
space:
mode:
authorcwm <chriswmartin@protonmail.com>2017-12-10 15:22:15 -0600
committercwm <chriswmartin@protonmail.com>2017-12-10 15:22:15 -0600
commit072ab191cc47692bad1145a26aa27912aeefb12f (patch)
treed217dc63f36554c7271b1c68a90d8d044640a732 /config
parenteec5d350fdb94fa44c6938ca059166ff3e3e67b3 (diff)
parent26c9b9fa276fd629789fd06f65a5d698b182f67a (diff)
pulled master, moved locale entry to new location
Diffstat (limited to 'config')
-rw-r--r--config/initializers/locale.rb6
-rw-r--r--config/locales/ca.yml2
-rw-r--r--config/locales/en.yml2
-rw-r--r--config/locales/es.yml2
-rw-r--r--config/locales/fr.yml2
-rw-r--r--config/locales/pl.yml2
-rw-r--r--config/webpack/configuration.js5
-rw-r--r--config/webpack/generateLocalePacks.js108
-rw-r--r--config/webpack/shared.js11
9 files changed, 65 insertions, 75 deletions
diff --git a/config/initializers/locale.rb b/config/initializers/locale.rb
new file mode 100644
index 000000000..04ed31646
--- /dev/null
+++ b/config/initializers/locale.rb
@@ -0,0 +1,6 @@
+# frozen_string_literal: true
+
+I18n.load_path += Dir[Rails.root.join('app', 'javascript', 'flavours', '*', 'names.{rb,yml}').to_s]
+I18n.load_path += Dir[Rails.root.join('app', 'javascript', 'flavours', '*', 'names', '*.{rb,yml}').to_s]
+I18n.load_path += Dir[Rails.root.join('app', 'javascript', 'skins', '*', '*', 'names.{rb,yml}').to_s]
+I18n.load_path += Dir[Rails.root.join('app', 'javascript', 'skins', '*', '*', 'names', '*.{rb,yml}').to_s]
diff --git a/config/locales/ca.yml b/config/locales/ca.yml
index 357e39e31..05c08c01a 100644
--- a/config/locales/ca.yml
+++ b/config/locales/ca.yml
@@ -678,8 +678,6 @@ ca:
 
       <p>Originalment adaptat a la <a href="https://github.com/discourse/discourse">política de privadesa del Discurs</a>.</p>
     title: "%{instance} Condicions del servei i política de privadesa"
-  themes:
-    default: Mastodont
   time:
     formats:
       default: "%b %d, %Y, %H:%M"
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 0ca320e1a..c8acc237a 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -687,8 +687,6 @@ en:
 
       <p>Originally adapted from the <a href="https://github.com/discourse/discourse">Discourse privacy policy</a>.</p>
     title: "%{instance} Terms of Service and Privacy Policy"
-  themes:
-    default: Mastodon
   time:
     formats:
       default: "%b %d, %Y, %H:%M"
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 18b93b08e..d9084787d 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -678,8 +678,6 @@ es:
 
       <p>Adaptado originalmente del <a href="https://github.com/discourse/discourse">discurso de las políticas de privacidad</a>.</p>
     title: Términos del Servicio y Políticas de Privacidad de %{instance}
-  themes:
-    default: Mastodon
   time:
     formats:
       default: "%d de %b del %Y, %H:%M"
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index cd97f5967..45243d07e 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -677,8 +677,6 @@ fr:
 
       <p>Originellement adapté à partir de la politique de confidentialité de <a href="https://github.com/discourse/discourse">Discourse</a>.</p>
     title: "%{instance} Conditions d’utilisations et politique de confidentialité"
-  themes:
-    default: Mastodon
   time:
     formats:
       default: "%d %b %Y, %H:%M"
diff --git a/config/locales/pl.yml b/config/locales/pl.yml
index baa26f1dc..582a2cd03 100644
--- a/config/locales/pl.yml
+++ b/config/locales/pl.yml
@@ -693,8 +693,6 @@ pl:
 
       <p>Tekst bazuje na <a href="https://github.com/discourse/discourse">polityce prywatności Discourse</a>.</p>
     title: Zasady korzystania i polityka prywatności %{instance}
-  themes:
-    default: Mastodon
   time:
     formats:
       default: "%b %d, %Y, %H:%M"
diff --git a/config/webpack/configuration.js b/config/webpack/configuration.js
index 9cdd6f934..852185eb9 100644
--- a/config/webpack/configuration.js
+++ b/config/webpack/configuration.js
@@ -30,6 +30,9 @@ for (let i = 0; i < flavourFiles.length; i++) {
   if (!data.pack_directory) {
     data.pack_directory = dirname(flavourFile);
   }
+  if (data.locales) {
+    data.locales = join(dirname(flavourFile), data.locales);
+  }
   if (data.pack && typeof data.pack === 'object') {
     flavours[data.name] = data;
   }
@@ -45,7 +48,7 @@ for (let i = 0; i < skinFiles.length; i++) {
   const data = flavours[name].skin;
   if (lstatSync(skinFile).isDirectory()) {
     data[skin] = {};
-    const skinPacks = glob.sync(resolve(skinFile, '*.{css,scss}'));
+    const skinPacks = glob.sync(join(skinFile, '*.{css,scss}'));
     for (let j = 0; j < skinPacks.length; j++) {
       const pack = skinPacks[i];
       data[skin][basename(pack, extname(pack))] = pack;
diff --git a/config/webpack/generateLocalePacks.js b/config/webpack/generateLocalePacks.js
index a943589f7..09fba4a18 100644
--- a/config/webpack/generateLocalePacks.js
+++ b/config/webpack/generateLocalePacks.js
@@ -1,70 +1,66 @@
+// A message from upstream:
+// ========================
 // To avoid adding a lot of boilerplate, locale packs are
 // automatically generated here. These are written into the tmp/
 // directory and then used to generate locale_en.js, locale_fr.js, etc.
 
-const fs = require('fs');
-const path = require('path');
+// Glitch note:
+// ============
+// This code has been entirely rewritten to support glitch flavours.
+// However, the underlying process is exactly the same.
+
+const { existsSync, readdirSync, writeFileSync } = require('fs');
+const { join, resolve } = require('path');
 const rimraf = require('rimraf');
 const mkdirp = require('mkdirp');
+const { flavours } = require('./configuration.js');
 
-const localesJsonPath = path.join(__dirname, '../../app/javascript/mastodon/locales');
-const locales = fs.readdirSync(localesJsonPath).filter(filename => {
-  return /\.json$/.test(filename) &&
-    !/defaultMessages/.test(filename) &&
-    !/whitelist/.test(filename);
-}).map(filename => filename.replace(/\.json$/, ''));
-
-const outPath = path.join(__dirname, '../../tmp/packs');
-
-rimraf.sync(outPath);
-mkdirp.sync(outPath);
-
-const outPaths = [];
-
-locales.forEach(locale => {
-  const localePath = path.join(outPath, `locale_${locale}.js`);
-  const baseLocale = locale.split('-')[0]; // e.g. 'zh-TW' -> 'zh'
-  const localeDataPath = [
-    // first try react-intl
-    `../../node_modules/react-intl/locale-data/${baseLocale}.js`,
-    // then check locales/locale-data
-    `../../app/javascript/mastodon/locales/locale-data/${baseLocale}.js`,
-    // fall back to English (this is what react-intl does anyway)
-    '../../node_modules/react-intl/locale-data/en.js',
-  ].filter(filename => fs.existsSync(path.join(outPath, filename)))
-    .map(filename => filename.replace(/..\/..\/node_modules\//, ''))[0];
-
-  let glitchInject = `
-const mergedMessages = messages;
-`;
-
-  const glitchPath = `../../app/javascript/glitch/locales/${locale}.json`;
-  if (fs.existsSync(path.join(outPath, glitchPath))) {
-    glitchInject = `
-import glitchMessages from ${JSON.stringify(glitchPath)};
-
-let mergedMessages = messages;
-Object.keys(glitchMessages).forEach(function (key) {
-   mergedMessages[key] = glitchMessages[key];
-});
-
-`;
+module.exports = Object.keys(flavours).reduce(function (map, entry) {
+  const flavour = flavours[entry];
+  if (!flavour.locales) {
+    return map;
   }
+  const locales = readdirSync(flavour.locales).filter(
+    filename => /\.js(?:on)?$/.test(filename) && !/defaultMessages|whitelist|index/.test(filename)
+  );
+  const outPath = resolve('tmp', 'locales', entry);
+
+  rimraf.sync(outPath);
+  mkdirp.sync(outPath);
 
-  const localeContent = `//
-// locale_${locale}.js
+  locales.forEach(function (locale) {
+    const localeName = locale.replace(/\.js(?:on)?$/, '');
+    const localePath = join(outPath, `${localeName}.js`);
+    const baseLocale = localeName.split('-')[0]; // e.g. 'zh-TW' -> 'zh'
+    const localeDataPath = [
+      // first try react-intl
+      `node_modules/react-intl/locale-data/${baseLocale}.js`,
+      // then check locales/locale-data
+      `app/javascript/locales/locale-data/${baseLocale}.js`,
+      // fall back to English (this is what react-intl does anyway)
+      'node_modules/react-intl/locale-data/en.js',
+    ].filter(
+      filename => existsSync(filename)
+    ).map(
+      filename => filename.replace(/(?:node_modules|app\/javascript)\//, '')
+    )[0];
+    const localeContent = `//
+// locales/${entry}/${localeName}.js
 // automatically generated by generateLocalePacks.js
 //
-import messages from '../../app/javascript/mastodon/locales/${locale}.json';
-import localeData from ${JSON.stringify(localeDataPath)};
-import { setLocale } from 'locales';
-${glitchInject}
-setLocale({messages: mergedMessages, localeData: localeData});
-`;
-  fs.writeFileSync(localePath, localeContent, 'utf8');
-  outPaths.push(localePath);
-});
 
-module.exports = outPaths;
+import messages from '../../../${flavour.locales}/${locale.replace(/\.js$/, '')}';
+import localeData from '${localeDataPath}';
+import { setLocale } from 'locales';
 
+setLocale({
+  localeData,
+  messages,
+});
+`;
+    writeFileSync(localePath, localeContent, 'utf8');
+    map[`locales/${entry}/${localeName}`] = localePath;
+  });
 
+  return map;
+}, {});
diff --git a/config/webpack/shared.js b/config/webpack/shared.js
index e4b057ffb..35b9bbd1c 100644
--- a/config/webpack/shared.js
+++ b/config/webpack/shared.js
@@ -1,13 +1,12 @@
 // Note: You must restart bin/webpack-dev-server for changes to take effect
 
 const webpack = require('webpack');
-const { basename, join, resolve } = require('path');
+const { join, resolve } = require('path');
 const { sync } = require('glob');
 const ExtractTextPlugin = require('extract-text-webpack-plugin');
 const ManifestPlugin = require('webpack-manifest-plugin');
-const extname = require('path-complete-extname');
 const { env, settings, core, flavours, output, loadersDir } = require('./configuration.js');
-const localePackPaths = require('./generateLocalePacks');
+const localePacks = require('./generateLocalePacks');
 
 function reducePacks (data, into = {}) {
   if (!data.pack) {
@@ -48,11 +47,7 @@ function reducePacks (data, into = {}) {
 module.exports = {
   entry: Object.assign(
     { locales: resolve('app', 'javascript', 'locales') },
-    localePackPaths.reduce((map, entry) => {
-      const localMap = map;
-      localMap[basename(entry, extname(entry, extname(entry)))] = resolve(entry);
-      return localMap;
-    }, {}),
+    localePacks,
     reducePacks(core),
     Object.keys(flavours).reduce((map, entry) => reducePacks(flavours[entry], map), {})
   ),