From ec146c7f450c8d1a589a36f94ac5221137067379 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 25 May 2017 11:24:17 +0100 Subject: [PATCH] Switch to stock counterpart We no longer need the custom counterpart. The things that were changed in it and reasosn we no lomger need them are: 1. set separator - this can be done with standard counterpart 2. ES6 port: this was done to allow importing as _t, but is unnecessary with the _t wrapper function in react-sdk (although also seems to work fine with `import _t from 'counterpart';`) 3. Fallback to key name: unnecessary with `setMissingEntryGenerator` in 0.18, but we've changed to just using a fallback locale anyway since No code missing en translations should ever make it to the devbelop branch. 4. Logging on missing translations. Unnecessary with `onTranslationNotFound`, but now not used anyway because we let missing translations show up in the UI as 'missing translation' Bulk changes to imports coming in separate commit for easy reading. --- package.json | 2 +- src/languageHandler.js | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 11106325f1..b94c8d66eb 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "browser-request": "^0.3.3", "classnames": "^2.1.2", "commonmark": "^0.27.0", - "counterpart-riot": "^0.18.1", + "counterpart": "^0.18.0", "draft-js": "^0.8.1", "draft-js-export-html": "^0.5.0", "draft-js-export-markdown": "^0.2.0", diff --git a/src/languageHandler.js b/src/languageHandler.js index 92e3ccefb6..25c380a53c 100644 --- a/src/languageHandler.js +++ b/src/languageHandler.js @@ -1,5 +1,6 @@ /* Copyright 2017 MTRNord and Cooperative EITA +Copyright 2017 Vector Creations Ltd. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,13 +16,27 @@ limitations under the License. */ import request from 'browser-request'; -// Workaround for broken export -import * as counterpart from 'counterpart-riot'; -import UserSettingsStore from './UserSettingsStore'; +import counterpart from 'counterpart'; import q from 'q'; +import UserSettingsStore from './UserSettingsStore'; + const i18nFolder = 'i18n/'; +// We use english strings as keys, some of which contain full stops +counterpart.setSeparator('|'); +// Fall back to English +counterpart.setFallbackLocale('en'); + +// The translation function. This is just a simple wrapper to counterpart, +// but exists mostly because we must use the same counterpart instance +// between modules (ie. here (react-sdk) and the app (riot-web), and if we +// just import counterpart and use it directly, we end up using a different +// instance. +export function _t(...args) { + return counterpart.translate(...args); +} + export function setLanguage(languages, extCounterpart=null) { if (!languages || !Array.isArray(languages)) { const languages = this.getNormalizedLanguageKeys(this.getLanguageFromBrowser());