Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #29459 from stasm/1153199-src
Browse files Browse the repository at this point in the history
Bug 1153199 - Re-organize directory layout in l10n.js upstream repo. r=gandalf
  • Loading branch information
stasm committed Apr 13, 2015
2 parents 4da142c + 8176d19 commit 130079e
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 97 deletions.
6 changes: 2 additions & 4 deletions apps/sharedtest/test/unit/l10n/lib/context/basic_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global assert:true, it, describe, beforeEach */
/* global navigator, process, __dirname */
/* global navigator, __dirname */
'use strict';

if (typeof navigator !== 'undefined') {
Expand All @@ -11,9 +11,7 @@ if (typeof navigator !== 'undefined') {
};
} else {
var assert = require('assert');
var L20n = process.env.L20N_COV ?
require('../../../build/cov/lib/l20n')
: require('../../../lib/l20n');
var L20n = require('../../../src/bindings/node');
}

if (typeof navigator !== 'undefined') {
Expand Down
6 changes: 2 additions & 4 deletions apps/sharedtest/test/unit/l10n/lib/context/fallback_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global assert:true, it, describe, beforeEach */
/* global navigator, process, __dirname */
/* global navigator, __dirname */
'use strict';

if (typeof navigator !== 'undefined') {
Expand All @@ -9,9 +9,7 @@ if (typeof navigator !== 'undefined') {
'app://sharedtest.gaiamobile.org/test/unit/l10n/lib/context';
} else {
var assert = require('assert');
var Context = process.env.L20N_COV ?
require('../../../build/cov/lib/l20n/context').Context
: require('../../../lib/l20n/context').Context;
var Context = require('../../../src/lib/context').Context;
var path = __dirname;
}

Expand Down
6 changes: 2 additions & 4 deletions apps/sharedtest/test/unit/l10n/lib/context/format_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global assert:true, it, describe, beforeEach */
/* global navigator, process, __dirname */
/* global navigator, __dirname */
'use strict';

if (typeof navigator !== 'undefined') {
Expand All @@ -9,9 +9,7 @@ if (typeof navigator !== 'undefined') {
'app://sharedtest.gaiamobile.org/test/unit/l10n/lib/context';
} else {
var assert = require('assert');
var Context = process.env.L20N_COV ?
require('../../../build/cov/lib/l20n/context').Context
: require('../../../lib/l20n/context').Context;
var Context = require('../../../src/lib/context').Context;
var path = __dirname;
}

Expand Down
6 changes: 2 additions & 4 deletions apps/sharedtest/test/unit/l10n/lib/context/langnego_test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/* global assert:true, it, describe, beforeEach */
/* global navigator, process */
/* global navigator */
'use strict';

if (typeof navigator !== 'undefined') {
var L10n = navigator.mozL10n._getInternalAPI();
var Context = L10n.Context;
} else {
var assert = require('assert');
var Context = process.env.L20N_COV ?
require('../../../build/cov/lib/l20n/context').Context
: require('../../../lib/l20n/context').Context;
var Context = require('../../../src/lib/context').Context;
}

describe('Language negotiation without arguments', function() {
Expand Down
6 changes: 2 additions & 4 deletions apps/sharedtest/test/unit/l10n/lib/context/loading_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global assert:true, it, describe, beforeEach */
/* global navigator, process, __dirname */
/* global navigator, __dirname */
'use strict';

if (typeof navigator !== 'undefined') {
Expand All @@ -9,9 +9,7 @@ if (typeof navigator !== 'undefined') {
'app://sharedtest.gaiamobile.org/test/unit/l10n/lib/context';
} else {
var assert = require('assert');
var Context = process.env.L20N_COV ?
require('../../../build/cov/lib/l20n/context').Context
: require('../../../lib/l20n/context').Context;
var Context = require('../../../src/lib/context').Context;
var path = __dirname;
}

Expand Down
6 changes: 2 additions & 4 deletions apps/sharedtest/test/unit/l10n/lib/context/resources_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global assert:true, it, describe, beforeEach */
/* global navigator, process, __dirname */
/* global navigator, __dirname */
'use strict';

if (typeof navigator !== 'undefined') {
Expand All @@ -8,9 +8,7 @@ if (typeof navigator !== 'undefined') {
var path = 'app://sharedtest.gaiamobile.org/test/unit/l10n/context';
} else {
var assert = require('assert');
var Context = process.env.L20N_COV ?
require('../../../build/cov/lib/l20n/context').Context
: require('../../../lib/l20n/context').Context;
var Context = require('../../../src/lib/context').Context;
var path = __dirname;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
/* global it, describe, beforeEach */
/* global navigator, process */
/* global navigator */
'use strict';

if (typeof navigator !== 'undefined') {
var L10n = navigator.mozL10n._getInternalAPI();
var Context = L10n.Context;
} else {
var Context = process.env.L20N_COV ?
require('../../../build/cov/lib/l20n/context').Context
: require('../../../lib/l20n/context').Context;
var Context = require('../../../src/lib/context').Context;
}

describe('ctx.ready', function() {
Expand Down
6 changes: 2 additions & 4 deletions apps/sharedtest/test/unit/l10n/lib/parser/dos_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global assert:true, it, beforeEach, describe */
/* global navigator, process */
/* global navigator */
/* jshint -W101 */
'use strict';

Expand All @@ -8,9 +8,7 @@ if (typeof navigator !== 'undefined') {
} else {
var assert = require('assert');
var L10n = {
PropertiesParser: process.env.L20N_COV ?
require('../../../build/cov/lib/l20n/parser')
: require('../../../lib/l20n/format/properties/parser')
PropertiesParser: require('../../../src/lib/format/properties/parser')
};
}

Expand Down
6 changes: 2 additions & 4 deletions apps/sharedtest/test/unit/l10n/lib/parser/overlay_test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/* global it, assert:true, describe */
/* global navigator, process */
/* global navigator */
'use strict';

if (typeof navigator !== 'undefined') {
var L10n = navigator.mozL10n._getInternalAPI();
} else {
var assert = require('assert');
var L10n = {
PropertiesParser: process.env.L20N_COV ?
require('../../../build/cov/lib/l20n/parser')
: require('../../../lib/l20n/format/properties/parser')
PropertiesParser: require('../../../src/lib/format/properties/parser')
};
}

Expand Down
6 changes: 2 additions & 4 deletions apps/sharedtest/test/unit/l10n/lib/parser/parser_test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/* global it, assert:true, describe */
/* global navigator, process */
/* global navigator */
'use strict';

if (typeof navigator !== 'undefined') {
var L10n = navigator.mozL10n._getInternalAPI();
} else {
var assert = require('assert');
var L10n = {
PropertiesParser: process.env.L20N_COV ?
require('../../../build/cov/lib/l20n/parser')
: require('../../../lib/l20n/format/properties/parser')
PropertiesParser: require('../../../src/lib/format/properties/parser')
};
}

Expand Down
14 changes: 5 additions & 9 deletions apps/sharedtest/test/unit/l10n/lib/pseudo_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global it, assert:true, describe, before, beforeEach */
/* global navigator, process */
/* global navigator */
'use strict';

var assert;
Expand All @@ -19,14 +19,10 @@ describe('pseudo strategy', function() {
});
} else {
assert = require('assert');
PSEUDO = process.env.L20N_COV ?
require('../../build/cov/lib/l20n/pseudo').PSEUDO
: require('../../lib/l20n/pseudo').PSEUDO;
walkContent = require('../../lib/l20n/util').walkContent;

PropertiesParser = process.env.L20N_COV ?
require('../../build/cov/lib/l20n/parser')
: require('../../lib/l20n/format/properties/parser');
PSEUDO = require('../../src/lib/pseudo').PSEUDO;
walkContent = require('../../src/lib/util').walkContent;
PropertiesParser =
require('../../src/lib/format/properties/parser');
done();
}
});
Expand Down
10 changes: 4 additions & 6 deletions apps/sharedtest/test/unit/l10n/lib/resolver/header.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global navigator, process, exports */
/* global navigator, exports */
/* exported Resolver */

'use strict';
Expand All @@ -9,11 +9,9 @@ if (typeof navigator !== 'undefined') {
} else {
var L10n = {
PropertiesParser:
require('../../../lib/l20n/format/properties/parser'),
Resolver: process.env.L20N_COV ?
require('../../../build/cov/lib/l20n/resolver'):
require('../../../lib/l20n/resolver'),
getPluralRule: require('../../../lib/l20n/plurals').getPluralRule
require('../../../src/lib/format/properties/parser'),
Resolver: require('../../../src/lib/resolver'),
getPluralRule: require('../../../src/lib/plurals').getPluralRule
};

exports.createEntries = createEntries;
Expand Down
11 changes: 3 additions & 8 deletions apps/sharedtest/test/unit/l10n/lib/util_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global it, assert:true, describe, before, beforeEach */
/* global navigator, process */
/* global navigator */
'use strict';

var assert, PropertiesParser;
Expand Down Expand Up @@ -30,13 +30,8 @@ describe('walkContent', function() {
} else {
assert = require('assert');
L10n = {};
L10n.walkContent = process.env.L20N_COV ?
require('../../build/cov/lib/l20n/util').walkContent
: require('../../lib/l20n/util').walkContent;

PropertiesParser = process.env.L20N_COV ?
require('../../build/cov/lib/l20n/parser')
: require('../../lib/l20n/format/properties/parser');
L10n.walkContent = require('../../src/lib/util').walkContent;
PropertiesParser = require('../../src/lib/format/properties/parser');
done();
}
});
Expand Down
72 changes: 38 additions & 34 deletions shared/js/l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -1547,8 +1547,6 @@



var DEBUG = false;
var isPretranslated = false;
var rtlList = ['ar', 'he', 'fa', 'ps', 'qps-plocm', 'ur'];
var nodeObserver = null;
var pendingElements = null;
Expand All @@ -1564,7 +1562,7 @@
// Public API

navigator.mozL10n = {
ctx: new Context(window.document ? document.URL : null),
ctx: null,
get: function get(id, ctxdata) {
return navigator.mozL10n.ctx.get(id, ctxdata);
},
Expand Down Expand Up @@ -1603,6 +1601,7 @@
_config: {
appVersion: null,
localeSources: Object.create(null),
isPretranslated: false,
},
_getInternalAPI: function() {
return {
Expand All @@ -1621,24 +1620,6 @@
}
};

navigator.mozL10n.ctx.ready(onReady.bind(navigator.mozL10n));

navigator.mozL10n.ctx.addEventListener('notfounderror',
function reportMissingEntity(e) {
if (DEBUG || e.loc === 'en-US') {
console.warn(e.toString());
}
});

if (DEBUG) {
navigator.mozL10n.ctx.addEventListener('fetcherror',
console.error.bind(console));
navigator.mozL10n.ctx.addEventListener('parseerror',
console.error.bind(console));
navigator.mozL10n.ctx.addEventListener('resolveerror',
console.error.bind(console));
}

function getDirection(lang) {
return (rtlList.indexOf(lang) >= 0) ? 'rtl' : 'ltr';
}
Expand All @@ -1664,17 +1645,6 @@
});
}

if (window.document) {
isPretranslated = document.documentElement.lang === navigator.language;

// XXX always pretranslate if data-no-complete-bug is set; this is
// a workaround for a netError page not firing some onreadystatechange
// events; see https://bugzil.la/444165
var pretranslate = document.documentElement.dataset.noCompleteBug ?
true : !isPretranslated;
waitFor('interactive', init.bind(navigator.mozL10n, pretranslate));
}

function initObserver() {
nodeObserver = new MutationObserver(onMutations.bind(navigator.mozL10n));
nodeObserver.observe(document, moConfig);
Expand Down Expand Up @@ -1868,10 +1838,10 @@
}

function onReady() {
if (!isPretranslated) {
if (!navigator.mozL10n._config.isPretranslated) {
translateDocument.call(this);
}
isPretranslated = false;
navigator.mozL10n._config.isPretranslated = false;

if (pendingElements) {
/* jshint boss:true */
Expand Down Expand Up @@ -2121,4 +2091,38 @@
return index;
}


var DEBUG = false;

navigator.mozL10n.ctx = new Context(window.document ? document.URL : null);
navigator.mozL10n.ctx.ready(onReady.bind(navigator.mozL10n));

navigator.mozL10n.ctx.addEventListener('notfounderror',
function reportMissingEntity(e) {
if (DEBUG || e.loc === 'en-US') {
console.warn(e.toString());
}
});

if (DEBUG) {
navigator.mozL10n.ctx.addEventListener('fetcherror',
console.error.bind(console));
navigator.mozL10n.ctx.addEventListener('parseerror',
console.error.bind(console));
navigator.mozL10n.ctx.addEventListener('resolveerror',
console.error.bind(console));
}

if (window.document) {
navigator.mozL10n._config.isPretranslated =
document.documentElement.lang === navigator.language;

// XXX always pretranslate if data-no-complete-bug is set; this is
// a workaround for a netError page not firing some onreadystatechange
// events; see https://bugzil.la/444165
var pretranslate = document.documentElement.dataset.noCompleteBug ?
true : !navigator.mozL10n._config.isPretranslated;
waitFor('interactive', init.bind(navigator.mozL10n, pretranslate));
}

})(this);

0 comments on commit 130079e

Please sign in to comment.