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.
This commit is contained in:
Ingo Schommer 2016-09-13 23:03:09 +12:00
parent ee10dbb680
commit 2316b0da9f
5 changed files with 18 additions and 86 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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',