From b00a60ab71b2bd4640c8608d71805ba9caae97d9 Mon Sep 17 00:00:00 2001
From: enahum <nahumhbl@gmail.com>
Date: Wed, 1 Jun 2016 09:56:13 -0300
Subject: PLT-1800 Load server side locale from the config.json (#3135)

* PLT-1800 Load server side locale from the config.json

* Add support for locales with country specifics

* Fix localization on served locale file as plain/text

* Remove github.com/cloudfoundry/jibber_jabber as vendor dependency
---
 webapp/i18n/i18n.jsx | 40 ++++++++++++++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 6 deletions(-)

(limited to 'webapp/i18n/i18n.jsx')

diff --git a/webapp/i18n/i18n.jsx b/webapp/i18n/i18n.jsx
index 2214fd386..783cef975 100644
--- a/webapp/i18n/i18n.jsx
+++ b/webapp/i18n/i18n.jsx
@@ -4,7 +4,7 @@
 const es = require('!!file?name=i18n/[name].[ext]!./es.json');
 const fr = require('!!file?name=i18n/[name].[ext]!./fr.json');
 const ja = require('!!file?name=i18n/[name].[ext]!./ja.json');
-const pt = require('!!file?name=i18n/[name].[ext]!./pt.json');
+const pt_BR = require('!!file?name=i18n/[name].[ext]!./pt-BR.json'); //eslint-disable-line camelcase
 
 import {addLocaleData} from 'react-intl';
 import enLocaleData from 'react-intl/locale-data/en';
@@ -34,19 +34,47 @@ const languages = {
         name: '日本語 (Beta)',
         url: ja
     },
-    pt: {
-        value: 'pt',
+    'pt-BR': {
+        value: 'pt-BR',
         name: 'Portugues (Beta)',
-        url: pt
+        url: pt_BR
     }
 };
 
-export function getLanguages() {
+let availableLanguages = null;
+
+function setAvailableLanguages() {
+    const available = global.window.mm_config.AvailableLocales.split(',');
+
+    availableLanguages = {};
+
+    available.forEach((l) => {
+        if (languages[l]) {
+            availableLanguages[l] = languages[l];
+        }
+    });
+}
+
+export function getAllLanguages() {
     return languages;
 }
 
+export function getLanguages() {
+    if (!availableLanguages) {
+        setAvailableLanguages();
+    }
+    return availableLanguages;
+}
+
 export function getLanguageInfo(locale) {
-    return languages[locale];
+    if (!availableLanguages) {
+        setAvailableLanguages();
+    }
+    return availableLanguages[locale];
+}
+
+export function isLanguageAvailable(locale) {
+    return !!availableLanguages[locale];
 }
 
 export function safariFix(callback) {
-- 
cgit v1.2.3-1-g7c22

