From 2316b0da9fd18423c0246b7ce4a156f11d2e96a3 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 13 Sep 2016 23:03:09 +1200 Subject: [PATCH] API Remove i18n::js_i18n option The JavaScript i18n functionality in SilverStripe is used in the CMS as well as form field implementations. Form fields used to include their own JavaScript for usage outside of CMS. This now requires custom build tooling in a project. Hence there's no need for an i18n shim (i18nx.js), since the CMS always uses i18n support. --- View/Requirements_Backend.php | 44 +++++++++----------------- admin/client/src/bundles/lib.js | 1 - admin/client/src/i18nx.js | 55 --------------------------------- docs/en/04_Changelogs/4.0.0.md | 3 ++ webpack.config.js | 1 - 5 files changed, 18 insertions(+), 86 deletions(-) delete mode 100644 admin/client/src/i18nx.js diff --git a/View/Requirements_Backend.php b/View/Requirements_Backend.php index df4e4c21d..28a4fe6ce 100644 --- a/View/Requirements_Backend.php +++ b/View/Requirements_Backend.php @@ -931,43 +931,29 @@ class Requirements_Backend * 'framework/javascript/lang' * @param bool $return Return all relative file paths rather than including them in * requirements - * @param bool $langOnly Only include language files, not the base libraries * * @return array|null All relative files if $return is true, or null otherwise */ - public function add_i18n_javascript($langDir, $return = false, $langOnly = false) + public function add_i18n_javascript($langDir, $return = false) { $files = array(); $base = Director::baseFolder() . '/'; - if (i18n::config()->js_i18n) { - // Include i18n.js even if no languages are found. The fact that - // add_i18n_javascript() was called indicates that the methods in - // here are needed. - if (!$langOnly) { - $files[] = FRAMEWORK_DIR . '/client/dist/js/i18n.js'; - } - if (substr($langDir, -1) != '/') { - $langDir .= '/'; - } + if (substr($langDir, -1) != '/') { + $langDir .= '/'; + } - $candidates = array( - 'en.js', - 'en_US.js', - i18n::get_lang_from_locale(i18n::config()->default_locale) . '.js', - i18n::config()->default_locale . '.js', - i18n::get_lang_from_locale(i18n::get_locale()) . '.js', - i18n::get_locale() . '.js', - ); - foreach ($candidates as $candidate) { - if (file_exists($base . DIRECTORY_SEPARATOR . $langDir . $candidate)) { - $files[] = $langDir . $candidate; - } - } - } else { - // Stub i18n implementation for when i18n is disabled. - if (!$langOnly) { - $files[] = FRAMEWORK_DIR . '/client/dist/js/i18nx.js'; + $candidates = array( + 'en.js', + 'en_US.js', + i18n::get_lang_from_locale(i18n::config()->default_locale) . '.js', + i18n::config()->default_locale . '.js', + i18n::get_lang_from_locale(i18n::get_locale()) . '.js', + i18n::get_locale() . '.js', + ); + foreach ($candidates as $candidate) { + if (file_exists($base . DIRECTORY_SEPARATOR . $langDir . $candidate)) { + $files[] = $langDir . $candidate; } } diff --git a/admin/client/src/bundles/lib.js b/admin/client/src/bundles/lib.js index de5730806..d93584260 100644 --- a/admin/client/src/bundles/lib.js +++ b/admin/client/src/bundles/lib.js @@ -21,7 +21,6 @@ require('expose?ReactAddonsTestUtils!react-addons-test-utils'); require('expose?Page!page.js'); require('expose?BootstrapCollapse!bootstrap/dist/js/umd/collapse.js'); require('i18n.js'); -require('expose?i18nx!i18nx.js'); require('babel-polyfill'); require('../../../../thirdparty/jquery-ondemand/jquery.ondemand.js'); diff --git a/admin/client/src/i18nx.js b/admin/client/src/i18nx.js deleted file mode 100644 index 2c962fd99..000000000 --- a/admin/client/src/i18nx.js +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Stub implementation for i18n code. - * Use instead of framework/javascript/src/i18n.js - * if you want to use any SilverStripe javascript - * without internationalization support. - */ -class i18nx { - constructor() { - this.currentLocale = 'en_US'; - this.defaultLocale = 'en_US'; - } - - _t(entity, fallbackString, priority, context) { - return fallbackString; - } - - sprintf(s, ...params) { - if (params.length === 0) { - return s; - } - - const regx = new RegExp('(.?)(%s)', 'g'); - - let i = 0; - - return s.replace(regx, function (match, subMatch1, subMatch2, offset, string) { - // skip %%s - if (subMatch1 === '%') { - return match; - } - - return subMatch1 + params[i += 1]; - }); - } - - inject(s, map) { - const regx = new RegExp('\{([A-Za-z0-9_]*)\}', 'g'); - - return s.replace(regx, function (match, key, offset, string) { - return (map[key]) ? map[key] : match; - }); - } - - addDictionary() { - - } - - getDictionary() { - - } -}; - -let _i18nx = new i18nx(); - -export default _i18nx; diff --git a/docs/en/04_Changelogs/4.0.0.md b/docs/en/04_Changelogs/4.0.0.md index 600800e69..09ba1d997 100644 --- a/docs/en/04_Changelogs/4.0.0.md +++ b/docs/en/04_Changelogs/4.0.0.md @@ -144,6 +144,9 @@ If you have referenced these files elsewhere, please consider running the ES6 source files in `admin/client/src/legacy` through your own transpiling and bundle process. +This also includes JavaScript i18n support, and the removal of the `i18n::js_i18n` +configuration option used in `Requirements::add_i18n_javascript()`. + SilverStripe core is moving away from `Requirements::combine_files` in favour of Webpack as of 4.0. `Requirements::combine_files` is being considered for deprecation in future versions. diff --git a/webpack.config.js b/webpack.config.js index 41734ef60..e05733de1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -68,7 +68,6 @@ const config = [ 'components/Toolbar/Toolbar': 'Toolbar', 'deep-freeze-strict': 'DeepFreezeStrict', i18n: 'i18n', - i18nx: 'i18nx', jQuery: 'jQuery', 'lib/Backend': 'Backend', 'lib/ReducerRegister': 'ReducerRegister',