about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorNolan Lawson <nolan@nolanlawson.com>2017-05-22 06:06:06 -0700
committerEugen Rochko <eugen@zeonfederated.com>2017-05-22 15:06:06 +0200
commit9d04de1c8d3efb745cfcae3519cee016751b86ec (patch)
tree8242677e98f04c66acf6c0531d0741a238b3c360 /app
parent73e4468ff31337d1a0afdc70e1717cb5cfae2e82 (diff)
Only load Intl data for current language (#3130)
* Only load Intl data for current language

* Extract common chunk only from application.js and public.js

* Generate locale packs, avoid caching on window object
Diffstat (limited to 'app')
-rw-r--r--app/javascript/mastodon/containers/mastodon.js61
-rw-r--r--app/javascript/mastodon/locales/index.js66
-rwxr-xr-xapp/views/layouts/application.html.haml1
3 files changed, 14 insertions, 114 deletions
diff --git a/app/javascript/mastodon/containers/mastodon.js b/app/javascript/mastodon/containers/mastodon.js
index ac44063a2..1d481d890 100644
--- a/app/javascript/mastodon/containers/mastodon.js
+++ b/app/javascript/mastodon/containers/mastodon.js
@@ -41,34 +41,12 @@ import FavouritedStatuses from '../features/favourited_statuses';
 import Blocks from '../features/blocks';
 import Mutes from '../features/mutes';
 import Report from '../features/report';
-import { IntlProvider, addLocaleData } from 'react-intl';
-import ar from 'react-intl/locale-data/ar';
-import bg from 'react-intl/locale-data/bg';
-import ca from 'react-intl/locale-data/ca';
-import de from 'react-intl/locale-data/de';
-import en from 'react-intl/locale-data/en';
-import eo from 'react-intl/locale-data/eo';
-import es from 'react-intl/locale-data/es';
-import fa from 'react-intl/locale-data/fa';
-import fi from 'react-intl/locale-data/fi';
-import fr from 'react-intl/locale-data/fr';
-import he from 'react-intl/locale-data/he';
-import hr from 'react-intl/locale-data/hr';
-import hu from 'react-intl/locale-data/hu';
-import id from 'react-intl/locale-data/id';
-import it from 'react-intl/locale-data/it';
-import ja from 'react-intl/locale-data/ja';
-import nl from 'react-intl/locale-data/nl';
-import no from 'react-intl/locale-data/no';
-import oc from '../locales/locale-data/oc';
-import pt from 'react-intl/locale-data/pt';
-import ru from 'react-intl/locale-data/ru';
-import uk from 'react-intl/locale-data/uk';
-import zh from 'react-intl/locale-data/zh';
-import tr from 'react-intl/locale-data/tr';
-import getMessagesForLocale from '../locales';
 import { hydrateStore } from '../actions/store';
 import createStream from '../stream';
+import { IntlProvider, addLocaleData } from 'react-intl';
+import { getLocale } from '../locales';
+const { localeData, messages } = getLocale();
+addLocaleData(localeData);
 
 const store = configureStore();
 const initialState = JSON.parse(document.getElementById("initial-state").textContent);
@@ -78,33 +56,6 @@ const browserHistory = useRouterHistory(createBrowserHistory)({
   basename: '/web',
 });
 
-addLocaleData([
-  ...ar,
-  ...bg,
-  ...ca,
-  ...de,
-  ...en,
-  ...eo,
-  ...es,
-  ...fa,
-  ...fi,
-  ...fr,
-  ...he,
-  ...hr,
-  ...hu,
-  ...id,
-  ...it,
-  ...ja,
-  ...nl,
-  ...no,
-  ...oc,
-  ...pt,
-  ...ru,
-  ...uk,
-  ...zh,
-  ...tr,
-]);
-
 class Mastodon extends React.PureComponent {
 
   componentDidMount() {
@@ -145,7 +96,7 @@ class Mastodon extends React.PureComponent {
           store.dispatch(deleteFromTimelines(data.payload));
           break;
         case 'notification':
-          store.dispatch(updateNotifications(JSON.parse(data.payload), getMessagesForLocale(locale), locale));
+          store.dispatch(updateNotifications(JSON.parse(data.payload), messages, locale));
           break;
         }
       },
@@ -183,7 +134,7 @@ class Mastodon extends React.PureComponent {
     const { locale } = this.props;
 
     return (
-      <IntlProvider locale={locale} messages={getMessagesForLocale(locale)}>
+      <IntlProvider locale={locale} messages={messages}>
         <Provider store={store}>
           <Router history={browserHistory} render={applyRouterMiddleware(useScroll())}>
             <Route path='/' component={UI}>
diff --git a/app/javascript/mastodon/locales/index.js b/app/javascript/mastodon/locales/index.js
index 2c592026e..421cb7fab 100644
--- a/app/javascript/mastodon/locales/index.js
+++ b/app/javascript/mastodon/locales/index.js
@@ -1,61 +1,9 @@
-import ar from './ar.json';
-import en from './en.json';
-import ca from './ca.json';
-import de from './de.json';
-import es from './es.json';
-import fa from './fa.json';
-import he from './he.json';
-import hr from './hr.json';
-import hu from './hu.json';
-import io from './io.json';
-import it from './it.json';
-import fr from './fr.json';
-import nl from './nl.json';
-import no from './no.json';
-import oc from './oc.json';
-import pt from './pt.json';
-import pt_br from './pt-BR.json';
-import uk from './uk.json';
-import fi from './fi.json';
-import eo from './eo.json';
-import ru from './ru.json';
-import ja from './ja.json';
-import zh_hk from './zh-HK.json';
-import zh_cn from './zh-CN.json';
-import bg from './bg.json';
-import id from './id.json';
-import tr from './tr.json';
+let theLocale;
 
-const locales = {
-  ar,
-  en,
-  ca,
-  de,
-  es,
-  fa,
-  he,
-  hr,
-  hu,
-  io,
-  it,
-  fr,
-  nl,
-  no,
-  oc,
-  pt,
-  'pt-BR': pt_br,
-  uk,
-  fi,
-  eo,
-  ru,
-  ja,
-  'zh-HK': zh_hk,
-  'zh-CN': zh_cn,
-  bg,
-  id,
-  tr,
-};
+export function setLocale(locale) {
+  theLocale = locale;
+}
 
-export default function getMessagesForLocale(locale) {
-  return locales[locale];
-};
+export function getLocale() {
+  return theLocale;
+}
diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml
index 21590ae3c..f991bc74f 100755
--- a/app/views/layouts/application.html.haml
+++ b/app/views/layouts/application.html.haml
@@ -20,6 +20,7 @@
 
     = stylesheet_pack_tag 'application', media: 'all'
     = javascript_pack_tag 'common', integrity: true, crossorigin: 'anonymous'
+    = javascript_pack_tag "locale_#{I18n.locale}", integrity: true, crossorigin: 'anonymous'
     = csrf_meta_tags
 
     = yield :header_tags