pulled master, moved locale entry to new location

This commit is contained in:
cwm
2017-12-10 15:22:15 -06:00
77 changed files with 1611 additions and 175 deletions

View File

@@ -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]

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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 dutilisations et politique de confidentialité"
themes:
default: Mastodon
time:
formats:
default: "%d %b %Y, %H:%M"

View File

@@ -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"

View File

@@ -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;

View File

@@ -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);
const localeContent = `//
// locale_${locale}.js
rimraf.sync(outPath);
mkdirp.sync(outPath);
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 messages from '../../../${flavour.locales}/${locale.replace(/\.js$/, '')}';
import localeData from '${localeDataPath}';
import { setLocale } from 'locales';
${glitchInject}
setLocale({messages: mergedMessages, localeData: localeData});
`;
fs.writeFileSync(localePath, localeContent, 'utf8');
outPaths.push(localePath);
setLocale({
localeData,
messages,
});
`;
writeFileSync(localePath, localeContent, 'utf8');
map[`locales/${entry}/${localeName}`] = localePath;
});
module.exports = outPaths;
return map;
}, {});

View File

@@ -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), {})
),