mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Fall back to en strings (fixes #738)
This commit is contained in:
@@ -6,9 +6,11 @@ locale.current = function(_) {
|
||||
return locale;
|
||||
};
|
||||
|
||||
function t(s, o) {
|
||||
function t(s, o, loc) {
|
||||
loc = loc || locale._current;
|
||||
|
||||
var path = s.split(".").reverse(),
|
||||
rep = locale[locale._current];
|
||||
rep = locale[loc];
|
||||
|
||||
while (rep !== undefined && path.length) rep = rep[path.pop()];
|
||||
|
||||
@@ -16,6 +18,9 @@ function t(s, o) {
|
||||
if (o) for (var k in o) rep = rep.replace('{' + k + '}', o[k]);
|
||||
return rep;
|
||||
} else {
|
||||
if (console) console.error('key ' + s + ' not found');
|
||||
var missing = 'Missing translation: ' + s;
|
||||
if (console) console.error(missing);
|
||||
if (loc !== 'en') return t(s, o, 'en');
|
||||
return missing;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +144,7 @@
|
||||
|
||||
<!-- include spec files here... -->
|
||||
<script src="spec/lib/d3.keybinding.js"></script>
|
||||
<script src="spec/lib/locale.js"></script>
|
||||
|
||||
<script src="spec/actions/add_midpoint.js"></script>
|
||||
<script src="spec/actions/add_entity.js"></script>
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
<!-- include spec files here... -->
|
||||
<script src="spec/lib/d3.keybinding.js"></script>
|
||||
<script src="spec/lib/locale.js"></script>
|
||||
|
||||
<script src="spec/actions/add_midpoint.js"></script>
|
||||
<script src="spec/actions/add_entity.js"></script>
|
||||
|
||||
26
test/spec/lib/locale.js
Normal file
26
test/spec/lib/locale.js
Normal file
@@ -0,0 +1,26 @@
|
||||
describe("locale", function() {
|
||||
var saved, error;
|
||||
|
||||
beforeEach(function() {
|
||||
saved = locale;
|
||||
error = console.error;
|
||||
console.error = function () {};
|
||||
locale = { _current: 'en', en: {test: 'test', foo: 'bar'}, __: {}}
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
locale = saved;
|
||||
console.error = error;
|
||||
});
|
||||
|
||||
describe("t", function() {
|
||||
it("defaults to locale._current", function() {
|
||||
expect(t('test')).to.equal('test');
|
||||
});
|
||||
|
||||
it("falls back to en", function() {
|
||||
locale._current = '__';
|
||||
expect(t('test')).to.equal('test');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user