Skip to content

Commit

Permalink
Language Control: Populate with available languages
Browse files Browse the repository at this point in the history
  • Loading branch information
maurofmferrao committed Nov 7, 2023
1 parent 04dac8a commit d159688
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 20 deletions.
2 changes: 1 addition & 1 deletion modules/clock-digital.xml
Expand Up @@ -63,7 +63,7 @@
<option name="LLLL">Localised - Month name, day of month, day of week, year, time</option>
</options>
</property>
<property id="lang" type="languageSelector">
<property id="lang" type="languageSelector" variant="momentLocales">
<title>Language</title>
<helpText>Select the language you would like to use.</helpText>
</property>
Expand Down
1 change: 1 addition & 0 deletions ui/bundle_vendor.js
Expand Up @@ -48,6 +48,7 @@ require('bootstrap-colorpicker');

// momentjs
window.moment = require('moment');
require('moment/min/locales');

// moment-timezone
require('moment-timezone');
Expand Down
40 changes: 40 additions & 0 deletions ui/src/core/forms.js
Expand Up @@ -981,6 +981,46 @@ window.forms = {
}
});

findElements(
'.languageSelect',
target,
).each(function(_k, el) {
const $select = $(el).find('select.form-control');
const isMomentLocaleSelect = $(el).hasClass('momentLocales');

if (isMomentLocaleSelect) {
const momentLocales = moment.locales().sort();
const selectValue = $select.val();

// Remove all previous options
$select.find('option').remove();

// Add empty option to the start of the array
momentLocales.unshift('');

// Add options from moment
for (let index = 0; index < momentLocales.length; index++) {
const locale = momentLocales[index];

// Get translation if exists
const name = momentLocalesTrans[locale] || locale;

// Create new option
const $newOption =
$(`<option value="${locale}">${locale} - ${name}</option>`);

// Check if it's selected
if (selectValue == locale) {
$newOption.prop('selected', true);
}

$newOption.appendTo($select);
}
}

makeLocalSelect($select, container);
});

// Playlist mixer
findElements(
'.playlist-mixer',
Expand Down
129 changes: 110 additions & 19 deletions ui/src/templates/forms/inputs/languageSelector.hbs
@@ -1,51 +1,142 @@
{{> dropdown id=id name=name title=title
value=value
selectType="localSelect"
selectType="languageSelect"
variant=variant
optionsTitle="title" optionsValue="name"
options=(arr
(obj name=null title='')
(obj name='af' title='Afrikaans')
(obj name='ar-dz' title='Arabic (Algeria)')
(obj name='ar-kw' title='Arabic (Kuwait)')
(obj name='ar-ly' title='Arabic (Libya)')
(obj name='ar-ma' title='Arabic (Morocco)')
(obj name='ar-sa' title='Arabic (Saudi Arabia)')
(obj name='ar-tn' title='Arabic (Tunisia)')
(obj name='ar' title='Arabic')
(obj name='az' title='Azerbaijani')
(obj name='az' title='Azerbaijani')
(obj name='be' title='Belarusian')
(obj name='bg' title='Bulgarian')
(obj name='bm' title='Bambara')
(obj name='bn-bd' title='Bengali (Bangladesh)')
(obj name='bn' title='Bengali')
(obj name='bo' title='Tibetan')
(obj name='br' title='Breton')
(obj name='bs' title='Bosnian')
(obj name='ca' title='Catalan')
(obj name='zh_cn' title='Chinese Simplified')
(obj name='zh_tw' title='Chinese Traditional')
(obj name='cz' title='Czech')
(obj name='cs' title='Czech')
(obj name='cv' title='Chuvash')
(obj name='cy' title='Welsh')
(obj name='da' title='Danish')
(obj name='de-at' title='German (Austria)')
(obj name='de-ch' title='German (Switzerland)')
(obj name='de' title='German')
(obj name='dv' title='Divehi')
(obj name='el' title='Greek')
(obj name='en' title='English')
(obj name='eu' title='Basque')
(obj name='fa' title='Persian (Farsi)')
(obj name='en-au' title='English (Australia)')
(obj name='en-ca' title='English (Canada)')
(obj name='en-gb' title='English (United Kingdom)')
(obj name='en-ie' title='English (Ireland)')
(obj name='en-il' title='English (Israel)')
(obj name='en-in' title='English (India)')
(obj name='en-nz' title='English (New Zealand)')
(obj name='en-sg' title='English (Singapore)')
(obj name='eo' title='Esperanto')
(obj name='es-do' title='Spanish (Dominican Republic)')
(obj name='es-mx' title='Spanish (Mexico)')
(obj name='es-us' title='Spanish (United States)')
(obj name='es' title='Spanish')
(obj name='et' title='Estonian')
(obj name='eu' title='Basque')
(obj name='fa' title='Persian')
(obj name='fi' title='Finnish')
(obj name='fil' title='Filipino')
(obj name='fo' title='Faroese')
(obj name='fr-ca' title='French (Canada)')
(obj name='fr-ch' title='French (Switzerland)')
(obj name='fr' title='French')
(obj name='fy' title='Western Frisian')
(obj name='gd' title='Scottish Gaelic')
(obj name='gl' title='Galician')
(obj name='gom-latn' title='gom (Latin)')
(obj name='gu' title='Gujarati')
(obj name='he' title='Hebrew')
(obj name='hi' title='Hindi')
(obj name='hr' title='Croatian')
(obj name='hu' title='Hungarian')
(obj name='hy-am' title='Armenian (Armenia)')
(obj name='id' title='Indonesian')
(obj name='is' title='Icelandic')
(obj name='it' title='Italian')
(obj name='it-ch' title='Italian (Switzerland)')
(obj name='it' title='Italian')
(obj name='ja' title='Japanese')
(obj name='jv' title='Javanese')
(obj name='ka' title='Georgian')
(obj name='kw' title='Cornish')
(obj name='nb' title='Norwegian Bokmal')
(obj name='kk' title='Kazakh')
(obj name='km' title='Khmer')
(obj name='kn' title='Kannada')
(obj name='ko' title='Korean')
(obj name='ku' title='Kurdish')
(obj name='ky' title='Kirghiz')
(obj name='lb' title='Luxembourgish')
(obj name='lo' title='Lao')
(obj name='lt' title='Lithuanian')
(obj name='lv' title='Latvian')
(obj name='me' title='Montenegrin')
(obj name='mi' title='Maori')
(obj name='mk' title='Macedonian')
(obj name='ml' title='Malayalam')
(obj name='mn' title='Mongolian')
(obj name='mr' title='Marathi')
(obj name='ms-my' title='Malay (Malaysia)')
(obj name='ms' title='Malay')
(obj name='mt' title='Maltese')
(obj name='my' title='Burmese')
(obj name='nb' title='Norwegian Bokmål')
(obj name='ne' title='Nepali')
(obj name='nl-be' title='Dutch (Belgium)')
(obj name='nl' title='Dutch')
(obj name='nn' title='Norwegian Nynorsk')
(obj name='pa-in' title='Punjabi (India)')
(obj name='pl' title='Polish')
(obj name='pt' title='Portuguese')
(obj name='pt_br' title='Portuguese (Brazil)')
(obj name='pt-br' title='Portuguese (Brazil)')
(obj name='pt' title='Portuguese')
(obj name='ro' title='Romanian')
(obj name='ru' title='Russian')
(obj name='ru' title='Russian')
(obj name='sd' title='Sindhi')
(obj name='se' title='Northern Sami')
(obj name='si' title='Sinhala')
(obj name='sk' title='Slovak')
(obj name='sl' title='Slovenian')
(obj name='es' title='Spanish')
(obj name='sl' title='Slovenian')
(obj name='sq' title='Albanian')
(obj name='sr-cyrl' title='Serbian (Cyrillic)')
(obj name='sr' title='Serbian')
(obj name='ss' title='Swati')
(obj name='sv' title='Swedish')
(obj name='sw' title='Swahili')
(obj name='ta' title='Tamil')
(obj name='te' title='Telugu')
(obj name='tet' title='Tetum')
(obj name='tr' title='Turkish')
(obj name='x-pig-latin' title='Igpay Atinlay')
(obj name='zh' title='Chinese Traditional')
(obj name='tg' title='Tajik')
(obj name='th' title='Thai')
(obj name='tk' title='Turkmen')
(obj name='tl-ph' title='Tagalog (Philippines)')
(obj name='tlh' title='Klingon')
(obj name='tr' title='Turkish')
(obj name='tzl' title='Talossan')
(obj name='tzm-latn' title='Central Atlas Tamazight (Latin)')
(obj name='tzm' title='Central Atlas Tamazight')
(obj name='ug-cn' title='Uyghur (China)')
(obj name='uk' title='Ukrainian')
(obj name='ur' title='Urdu')
(obj name='uz-latn' title='Uzbek (Latin)')
(obj name='uz' title='Uzbek')
(obj name='vi' title='Vietnamese')
(obj name='x-pseudo' title='Pseudo')
(obj name='yo' title='Yoruba (Nigeria)')
(obj name='zh-cn' title='Chinese (China)')
(obj name='zh-hk' title='Chinese (Hong Kong)')
(obj name='zh-mo' title='Chinese (Macau)')
(obj name='zh-tw' title='Chinese (Taiwan)')
)
customData=(arr
(obj name='allow-clear' value='true')
Expand Down
137 changes: 137 additions & 0 deletions views/common.twig
Expand Up @@ -953,6 +953,143 @@
scaleMode: "{{ "Change scale mode"|trans }}",
},
};
var momentLocalesTrans = {
"af": "{{ "Afrikaans"|trans }}",
"ar-dz": "{{ "Arabic (Algeria)"|trans }}",
"ar-kw": "{{ "Arabic (Kuwait)"|trans }}",
"ar-ly": "{{ "Arabic (Libya)"|trans }}",
"ar-ma": "{{ "Arabic (Morocco)"|trans }}",
"ar-sa": "{{ "Arabic (Saudi Arabia)"|trans }}",
"ar-tn": "{{ "Arabic (Tunisia)"|trans }}",
"ar": "{{ "Arabic"|trans }}",
"az": "{{ "Azerbaijani"|trans }}",
"be": "{{ "Belarusian"|trans }}",
"bg": "{{ "Bulgarian"|trans }}",
"bm": "{{ "Bambara"|trans }}",
"bn-bd": "{{ "Bengali (Bangladesh)"|trans }}",
"bn": "{{ "Bengali"|trans }}",
"bo": "{{ "Tibetan"|trans }}",
"br": "{{ "Breton"|trans }}",
"bs": "{{ "Bosnian"|trans }}",
"ca": "{{ "Catalan"|trans }}",
"cs": "{{ "Czech"|trans }}",
"cv": "{{ "Chuvash"|trans }}",
"cy": "{{ "Welsh"|trans }}",
"da": "{{ "Danish"|trans }}",
"de-at": "{{ "German (Austria)"|trans }}",
"de-ch": "{{ "German (Switzerland)"|trans }}",
"de": "{{ "German"|trans }}",
"dv": "{{ "Divehi"|trans }}",
"el": "{{ "Greek"|trans }}",
"en": "{{ "English"|trans }}",
"en-au": "{{ "English (Australia)"|trans }}",
"en-ca": "{{ "English (Canada)"|trans }}",
"en-gb": "{{ "English (United Kingdom)"|trans }}",
"en-GB": "{{ "English (United Kingdom)"|trans }}",
"en-ie": "{{ "English (Ireland)"|trans }}",
"en-il": "{{ "English (Israel)"|trans }}",
"en-in": "{{ "English (India)"|trans }}",
"en-nz": "{{ "English (New Zealand)"|trans }}",
"en-sg": "{{ "English (Singapore)"|trans }}",
"eo": "{{ "Esperanto"|trans }}",
"es-do": "{{ "Spanish (Dominican Republic)"|trans }}",
"es-mx": "{{ "Spanish (Mexico)"|trans }}",
"es-us": "{{ "Spanish (United States)"|trans }}",
"es": "{{ "Spanish"|trans }}",
"et": "{{ "Estonian"|trans }}",
"eu": "{{ "Basque"|trans }}",
"fa": "{{ "Persian"|trans }}",
"fi": "{{ "Finnish"|trans }}",
"fil": "{{ "Filipino"|trans }}",
"fo": "{{ "Faroese"|trans }}",
"fr-ca": "{{ "French (Canada)"|trans }}",
"fr-ch": "{{ "French (Switzerland)"|trans }}",
"fr": "{{ "French"|trans }}",
"fy": "{{ "Western Frisian"|trans }}",
"gd": "{{ "Scottish Gaelic"|trans }}",
"gl": "{{ "Galician"|trans }}",
"gom-latn": "{{ "gom (Latin)"|trans }}",
"gu": "{{ "Gujarati"|trans }}",
"he": "{{ "Hebrew"|trans }}",
"hi": "{{ "Hindi"|trans }}",
"hr": "{{ "Croatian"|trans }}",
"hu": "{{ "Hungarian"|trans }}",
"hy-am": "{{ "Armenian (Armenia)"|trans }}",
"id": "{{ "Indonesian"|trans }}",
"is": "{{ "Icelandic"|trans }}",
"it-ch": "{{ "Italian (Switzerland)"|trans }}",
"it": "{{ "Italian"|trans }}",
"ja": "{{ "Japanese"|trans }}",
"jv": "{{ "Javanese"|trans }}",
"ka": "{{ "Georgian"|trans }}",
"kk": "{{ "Kazakh"|trans }}",
"km": "{{ "Khmer"|trans }}",
"kn": "{{ "Kannada"|trans }}",
"ko": "{{ "Korean"|trans }}",
"ku": "{{ "Kurdish"|trans }}",
"ky": "{{ "Kirghiz"|trans }}",
"lb": "{{ "Luxembourgish"|trans }}",
"lo": "{{ "Lao"|trans }}",
"lt": "{{ "Lithuanian"|trans }}",
"lv": "{{ "Latvian"|trans }}",
"me": "{{ "Montenegrin"|trans }}",
"mi": "{{ "Maori"|trans }}",
"mk": "{{ "Macedonian"|trans }}",
"ml": "{{ "Malayalam"|trans }}",
"mn": "{{ "Mongolian"|trans }}",
"mr": "{{ "Marathi"|trans }}",
"ms-my": "{{ "Malay (Malaysia)"|trans }}",
"ms": "{{ "Malay"|trans }}",
"mt": "{{ "Maltese"|trans }}",
"my": "{{ "Burmese"|trans }}",
"nb": "{{ "Norwegian Bokmål"|trans }}",
"ne": "{{ "Nepali"|trans }}",
"nl-be": "{{ "Dutch (Belgium)"|trans }}",
"nl": "{{ "Dutch"|trans }}",
"nn": "{{ "Norwegian Nynorsk"|trans }}",
"pa-in": "{{ "Punjabi (India)"|trans }}",
"pl": "{{ "Polish"|trans }}",
"pt-br": "{{ "Portuguese (Brazil)"|trans }}",
"pt": "{{ "Portuguese"|trans }}",
"ro": "{{ "Romanian"|trans }}",
"ru": "{{ "Russian"|trans }}",
"sd": "{{ "Sindhi"|trans }}",
"se": "{{ "Northern Sami"|trans }}",
"si": "{{ "Sinhala"|trans }}",
"sk": "{{ "Slovak"|trans }}",
"sl": "{{ "Slovenian"|trans }}",
"sq": "{{ "Albanian"|trans }}",
"sr-cyrl": "{{ "Serbian (Cyrillic)"|trans }}",
"sr": "{{ "Serbian"|trans }}",
"ss": "{{ "Swati"|trans }}",
"sv": "{{ "Swedish"|trans }}",
"sw": "{{ "Swahili"|trans }}",
"ta": "{{ "Tamil"|trans }}",
"te": "{{ "Telugu"|trans }}",
"tet": "{{ "Tetum"|trans }}",
"tg": "{{ "Tajik"|trans }}",
"th": "{{ "Thai"|trans }}",
"tk": "{{ "Turkmen"|trans }}",
"tl-ph": "{{ "Tagalog (Philippines)"|trans }}",
"tlh": "{{ "Klingon"|trans }}",
"tr": "{{ "Turkish"|trans }}",
"tzl": "{{ "Talossan"|trans }}",
"tzm-latn": "{{ "Central Atlas Tamazight (Latin)"|trans }}",
"tzm": "{{ "Central Atlas Tamazight"|trans }}",
"ug-cn": "{{ "Uyghur (China)"|trans }}",
"uk": "{{ "Ukrainian"|trans }}",
"ur": "{{ "Urdu"|trans }}",
"uz-latn": "{{ "Uzbek (Latin)"|trans }}",
"uz": "{{ "Uzbek"|trans }}",
"vi": "{{ "Vietnamese"|trans }}",
"x-pseudo": "{{ "Pseudo"|trans }}",
"yo": "{{ "Yoruba (Nigeria)"|trans }}",
"zh-cn": "{{ "Chinese (China)"|trans }}",
"zh-hk": "{{ "Chinese (Hong Kong)"|trans }}",
"zh-mo": "{{ "Chinese (Macau)"|trans }}",
"zh-tw": "{{ "Chinese (Taiwan)"|trans }}",
};
{% endautoescape %}
</script>
{% endblock %}

0 comments on commit d159688

Please sign in to comment.