This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 914414 - Refactor l10n.js. r=vingtetun
- Loading branch information
Showing
19 changed files
with
1,971 additions
and
775 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* global it, assert:true, describe, beforeEach */ | ||
/* global window, navigator, process, __dirname */ | ||
'use strict'; | ||
|
||
var assert = require('assert') || window.assert; | ||
|
||
if (typeof navigator !== 'undefined') { | ||
var L10n = navigator.mozL10n._getInternalAPI(); | ||
var L20n = { | ||
getContext: function() { | ||
return new L10n.Context(); | ||
} | ||
}; | ||
} else { | ||
var L20n = process.env.L20N_COV ? | ||
require('../../../build/cov/lib/l20n') | ||
: require('../../../lib/l20n'); | ||
} | ||
|
||
if (typeof navigator !== 'undefined') { | ||
var path = 'http://gallery.gaiamobile.org:8080/test/unit/l10n/lib/context'; | ||
} else { | ||
var path = __dirname; | ||
} | ||
|
||
describe('A simple context with one resource', function() { | ||
var ctx; | ||
|
||
beforeEach(function(done) { | ||
ctx = L20n.getContext(); | ||
ctx.resLinks.push(path + '/fixtures/basic.properties'); | ||
ctx.ready(done); | ||
ctx.requestLocales('en-US'); | ||
}); | ||
|
||
it('should return the string value of brandName', function() { | ||
var value = ctx.get('brandName'); | ||
assert.strictEqual(value, 'Firefox'); | ||
}); | ||
|
||
it('should return the value of about with the value' + | ||
' of brandName in it', function() { | ||
var value = ctx.get('about'); | ||
assert.strictEqual(value, 'About Firefox'); | ||
}); | ||
|
||
it('should return the value of cert with the value of ' + | ||
'organization passed directly', function() { | ||
var value = ctx.get('cert', {organization: 'Mozilla Foundation'}); | ||
assert.strictEqual(value, 'Certificate signed by Mozilla Foundation'); | ||
}); | ||
|
||
it('should return the correct plural form for 0', function() { | ||
var value = ctx.get('unreadMessages', {unread: 0}); | ||
assert.strictEqual(value, '0 unread'); | ||
}); | ||
|
||
it('should return the correct plural form for 1', function() { | ||
var value = ctx.get('unreadMessages', {unread: 1}); | ||
assert.strictEqual(value, 'One unread'); | ||
}); | ||
|
||
it('should return the correct plural form for 2', function() { | ||
var value = ctx.get('unreadMessages', {unread: 2}); | ||
assert.strictEqual(value, '2 unread'); | ||
}); | ||
|
||
it('should return the correct plural form for 3', function() { | ||
var value = ctx.get('unreadMessages', {unread: 3}); | ||
assert.strictEqual(value, '3 unread'); | ||
}); | ||
|
||
}); |
124 changes: 124 additions & 0 deletions
124
apps/gallery/test/unit/l10n/lib/context/fallback_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* global it, assert:true, describe, beforeEach */ | ||
/* global window, navigator, process, __dirname */ | ||
'use strict'; | ||
|
||
var assert = require('assert') || window.assert; | ||
|
||
if (typeof navigator !== 'undefined') { | ||
var L10n = navigator.mozL10n._getInternalAPI(); | ||
var Context = L10n.Context; | ||
var path = 'http://gallery.gaiamobile.org:8080/test/unit/l10n/lib/context'; | ||
} else { | ||
var Context = process.env.L20N_COV ? | ||
require('../../../build/cov/lib/l20n/context').Context | ||
: require('../../../lib/l20n/context').Context; | ||
var path = __dirname; | ||
} | ||
|
||
describe('One fallback locale', function() { | ||
var ctx; | ||
|
||
beforeEach(function(done) { | ||
ctx = new Context(); | ||
ctx.resLinks.push(path + '/fixtures/{{locale}}.properties'); | ||
ctx.once(done); | ||
ctx.requestLocales('pl'); | ||
}); | ||
|
||
describe('Translation in the first locale exists and is OK', function() { | ||
it('[e]', function() { | ||
var entity = ctx.getEntity('e'); | ||
assert.strictEqual(entity, 'E pl'); | ||
}); | ||
}); | ||
|
||
describe('ValueError in first locale', function() { | ||
describe('Entity exists in second locale:', function() { | ||
it('[ve]', function() { | ||
var entity = ctx.getEntity('ve'); | ||
assert.strictEqual(entity, 'VE {{ boo }} pl'); | ||
}); | ||
}); | ||
|
||
describe('ValueError in second locale:', function() { | ||
it('[vv]', function() { | ||
var entity = ctx.getEntity('vv'); | ||
assert.strictEqual(entity, 'VV {{ boo }} pl'); | ||
}); | ||
}); | ||
|
||
describe('IndexError in second locale:', function() { | ||
it('[vi]', function() { | ||
var entity = ctx.getEntity('vi'); | ||
assert.strictEqual(entity, 'VI {{ boo }} pl'); | ||
}); | ||
}); | ||
|
||
describe('Entity missing in second locale:', function() { | ||
it('[vm]', function() { | ||
var entity = ctx.getEntity('vm'); | ||
assert.strictEqual(entity, 'VM {{ boo }} pl'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('IndexError in first locale', function() { | ||
describe('Entity exists in second locale', function() { | ||
it('[ie]', function() { | ||
var entity = ctx.getEntity('ie'); | ||
assert.strictEqual(entity, undefined); | ||
}); | ||
}); | ||
|
||
describe('ValueError in second locale', function() { | ||
it('[iv]', function() { | ||
var entity = ctx.getEntity('iv'); | ||
assert.strictEqual(entity, undefined); | ||
}); | ||
}); | ||
|
||
describe('IndexError in second locale', function() { | ||
it('[ii]', function() { | ||
var entity = ctx.getEntity('ii'); | ||
assert.strictEqual(entity, undefined); | ||
}); | ||
}); | ||
|
||
describe('Entity missing in second locale:', function() { | ||
it('[im]', function() { | ||
var entity = ctx.getEntity('im'); | ||
assert.strictEqual(entity, undefined); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Entity not found in first locale', function() { | ||
describe('Entity exists in second locale:', function() { | ||
it('[me]', function() { | ||
var entity = ctx.getEntity('me'); | ||
assert.strictEqual(entity, 'ME en-US'); | ||
}); | ||
}); | ||
|
||
describe('ValueError in second locale:', function() { | ||
it('[mv]', function() { | ||
var entity = ctx.getEntity('mv'); | ||
assert.strictEqual(entity, 'MV {{ boo }} en-US'); | ||
}); | ||
}); | ||
|
||
describe('IndexError in second locale:', function() { | ||
it('[mi]', function() { | ||
var entity = ctx.getEntity('mi'); | ||
assert.strictEqual(entity, undefined); | ||
}); | ||
}); | ||
|
||
describe('Entity missing in second locale:', function() { | ||
it('[mm]', function() { | ||
var entity = ctx.getEntity('mm'); | ||
assert.strictEqual(entity, null); | ||
}); | ||
}); | ||
}); | ||
}); |
6 changes: 6 additions & 0 deletions
6
apps/gallery/test/unit/l10n/lib/context/fixtures/basic.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
brandName=Firefox | ||
about=About {{ brandName }} | ||
cert=Certificate signed by {{ organization }} | ||
unreadMessages={[plural(unread)]} | ||
unreadMessages[one]=One unread | ||
unreadMessages[other]={{unread}} unread |
57 changes: 57 additions & 0 deletions
57
apps/gallery/test/unit/l10n/lib/context/fixtures/en-US.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
foo=Foo en-US | ||
|
||
# e - existing | ||
# v - ValueError | ||
# i - IndexError | ||
# m - missing | ||
|
||
me=ME en-US | ||
mv=MV {{ boo }} en-US | ||
mi={[plural(boo)]} | ||
mi[key]=MI en-US | ||
|
||
vve=VVE en-US | ||
vvv=VVV {{ boo }} en-US | ||
<vvi[boo] { key: "VVI en-US" }> | ||
|
||
vie=VIE en-US | ||
viv=VIV {{ boo }} en-US | ||
vii={[plural(boo)]} | ||
vii[key]=VII en-US | ||
|
||
vme=VME en-US | ||
vmv=VMV {{ boo }} en-US | ||
vmi={[plural(boo)]} | ||
vmi[key]=VMI en-US | ||
|
||
|
||
ive=IVE en-US | ||
ivv=IVV {{ boo }} en-US | ||
ivi={[plural(boo)]} | ||
ivi[key]=IVI en-US | ||
|
||
iie=IIE en-US | ||
iiv=IIV {{ boo }} en-US | ||
iii={[plural(boo)]} | ||
iii[key]=III en-US | ||
|
||
ime=IME en-US | ||
imv=IMV {{ boo }} en-US | ||
imi={[plural(boo)]} | ||
imi[key]=IMI en-US | ||
|
||
|
||
mve=MVE en-US | ||
mvv=MVV {{ boo }} en-US | ||
mvi={[plural(boo)]} | ||
mvi[key]=MVI en-US | ||
|
||
mie=MIE en-US | ||
miv=MIV {{ boo }} en-US | ||
mii={[plural(boo)]} | ||
mii[key]=MII en-US | ||
|
||
mme=MME en-US | ||
mmv=MMV {{ boo }} en-US | ||
mmi={[plural(boo)]} | ||
mmi[key]=MMI en-US |
Oops, something went wrong.