Allow for a partial dictionary in language
This closes https://github.com/select2/select2/issues/3202.
This commit is contained in:
parent
01160f29d8
commit
00a78bdb1e
9
dist/js/select2.full.js
vendored
9
dist/js/select2.full.js
vendored
@ -4471,7 +4471,14 @@ S2.define('select2/defaults',[
|
|||||||
|
|
||||||
options.translations = languages;
|
options.translations = languages;
|
||||||
} else {
|
} else {
|
||||||
options.translations = new Translation(options.language);
|
var baseTranslation = Translation.loadPath(
|
||||||
|
this.defaults.amdLanguageBase + 'en'
|
||||||
|
);
|
||||||
|
var customTranslation = new Translation(options.language);
|
||||||
|
|
||||||
|
customTranslation.extend(baseTranslation);
|
||||||
|
|
||||||
|
options.translations = customTranslation;
|
||||||
}
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
|
4
dist/js/select2.full.min.js
vendored
4
dist/js/select2.full.min.js
vendored
File diff suppressed because one or more lines are too long
9
dist/js/select2.js
vendored
9
dist/js/select2.js
vendored
@ -4471,7 +4471,14 @@ S2.define('select2/defaults',[
|
|||||||
|
|
||||||
options.translations = languages;
|
options.translations = languages;
|
||||||
} else {
|
} else {
|
||||||
options.translations = new Translation(options.language);
|
var baseTranslation = Translation.loadPath(
|
||||||
|
this.defaults.amdLanguageBase + 'en'
|
||||||
|
);
|
||||||
|
var customTranslation = new Translation(options.language);
|
||||||
|
|
||||||
|
customTranslation.extend(baseTranslation);
|
||||||
|
|
||||||
|
options.translations = customTranslation;
|
||||||
}
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
|
2
dist/js/select2.min.js
vendored
2
dist/js/select2.min.js
vendored
File diff suppressed because one or more lines are too long
9
src/js/select2/defaults.js
vendored
9
src/js/select2/defaults.js
vendored
@ -257,7 +257,14 @@ define([
|
|||||||
|
|
||||||
options.translations = languages;
|
options.translations = languages;
|
||||||
} else {
|
} else {
|
||||||
options.translations = new Translation(options.language);
|
var baseTranslation = Translation.loadPath(
|
||||||
|
this.defaults.amdLanguageBase + 'en'
|
||||||
|
);
|
||||||
|
var customTranslation = new Translation(options.language);
|
||||||
|
|
||||||
|
customTranslation.extend(baseTranslation);
|
||||||
|
|
||||||
|
options.translations = customTranslation;
|
||||||
}
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
|
28
tests/options/translation-tests.js
Normal file
28
tests/options/translation-tests.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
module('Options - Translations');
|
||||||
|
|
||||||
|
var $ = require('jquery');
|
||||||
|
var Options = require('select2/options');
|
||||||
|
|
||||||
|
test('partial dictionaries can be passed', function (assert) {
|
||||||
|
var options = new Options({
|
||||||
|
language: {
|
||||||
|
searching: function () {
|
||||||
|
return 'Something';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var translations = options.get('translations');
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
translations.get('searching')(),
|
||||||
|
'Something',
|
||||||
|
'The partial dictionary still overrides translations'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
translations.get('noResults')(),
|
||||||
|
'No results found',
|
||||||
|
'You can still get English translations for keys not passed in'
|
||||||
|
);
|
||||||
|
});
|
@ -71,6 +71,7 @@
|
|||||||
|
|
||||||
<script src="options/data-tests.js" type="text/javascript"></script>
|
<script src="options/data-tests.js" type="text/javascript"></script>
|
||||||
<script src="options/deprecated-tests.js" type="text/javascript"></script>
|
<script src="options/deprecated-tests.js" type="text/javascript"></script>
|
||||||
|
<script src="options/translation-tests.js" type="text/javascript"></script>
|
||||||
<script src="options/width-tests.js" type="text/javascript"></script>
|
<script src="options/width-tests.js" type="text/javascript"></script>
|
||||||
|
|
||||||
<script src="selection/allowClear-tests.js" type="text/javascript"></script>
|
<script src="selection/allowClear-tests.js" type="text/javascript"></script>
|
||||||
|
Loading…
Reference in New Issue
Block a user