VulpesOS/gaia/apps/settings/test/marionette/app/regions/language.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

134 lines
3.5 KiB
JavaScript
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
var Base = require('../base');
/**
* Abstraction around settings do not track panel
* @constructor
* @param {Marionette.Client} client for operations.
*/
function LanguagePanel(client) {
// Call the Base constructor to initiate base class.
Base.call(this, client, null, LanguagePanel.Selectors);
}
module.exports = LanguagePanel;
LanguagePanel.Selectors = {
'languagePanel': '#languages',
'body': 'body',
'header': 'gaia-header',
'languageChangeSelect': '#languages select[name="language.current"]',
'languageLabel': 'p[data-l10n-id="language"]',
'languageRegionDateLabel': '#region-date'
};
LanguagePanel.prototype = {
__proto__: Base.prototype,
// The \u202a, \u202b and \u202c are special Unicode formatting codes which
// force the direction of the text between them. They are added by
// LanguageList.wrapBidi to ensure proper display of all language names.
_languageMap: {
english: {
label: 'Language',
desc: '\u202aEnglish (US)\u202c',
dayRules: /Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday/
},
accented: {
label: 'Ŀȧȧƞɠŭŭȧȧɠḗḗ',
desc: '\u202aƤȧȧƈķȧȧɠḗḗḓ Ȧȧƈƈḗḗƞŧḗḗḓ\u202c',
dayRules: new RegExp(
'lundi|' +
'mardi|' +
'mercredi|' +
'jeudi|' +
'vendredi|' +
'samedi|' +
'dimanche')
},
bidi: {
label: '\u202e˥ɐuƃnɐƃǝ\u202c',
desc: '\u202b\u202eԀɐɔʞɐƃǝp\u202c \u202eԐıpı\u202c\u202c',
dayRules: new RegExp(
'الاثنين|' +
'الثلاثاء|' +
'الأربعاء|' +
'الخميس|' +
'الجمعة|' +
'السبت|' +
'الأحد')
}
},
get regionDateLabel() {
return this.findElement('languageRegionDateLabel').text();
},
get currentLanguageFromMozSettings() {
return this.client.settings.get('language.current');
},
get currentLanguageLabel() {
return this.findElement('languageLabel').text();
},
get currentLanguage() {
var languageLabel = this.currentLanguageLabel;
var realLanguage;
for (var languageKey in this._languageMap) {
if (this._languageMap[languageKey].label === languageLabel) {
realLanguage = languageKey;
break;
}
}
return realLanguage;
},
set currentLanguage(value) {
if (this._languageMap[value]) {
var oldLanguage = this.currentLanguage;
this.tapSelectOption('languageChangeSelect',
this._languageMap[value].desc);
this.client.waitFor(function() {
var newLanguage = this.currentLanguage;
return oldLanguage !== newLanguage;
}.bind(this));
}
},
setupDefaultLanguage: function() {
if (this.currentLanguage !== 'english') {
this.currentLanguage = 'english';
}
},
isSampleFormatTranslated: function(languageKey) {
if (this._languageMap[languageKey]) {
var rule = this._languageMap[languageKey].dayRules;
if (this.regionDateLabel.match(rule)) {
return true;
}
}
return false;
},
back: function() {
var parentSection = this.waitForElement('languagePanel');
var bodyWidth = this.findElement('body').size().width;
this.client.switchToShadowRoot(this.findElement('header'));
this.client.findElement('[action="back"] button').tap();
this.client.switchToShadowRoot();
this.client.waitFor(function() {
var loc = parentSection.location();
return Math.abs(loc.x) >= bodyWidth;
});
}
};