mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
259becea04
* whitespaces + typo fixes * JS / LGTM fixes * SSDP Handler crash fix * MessageForwarder handlePriorityChanges Slave fixes * use aboutToQuit Signal * complete rewriten Hue Entertainment API structure combined Philips Hue and Entertainment API with new MbedTLS based SSL UDP Provider * add required cross-compile submodules * logical rebuild fn: initLeds, setLights + new logs -more detailed checks and error handling inside iniLeds and setLights - logical script procedure before ProviderUdpSSL init - first steps for multiple ProviderUdpSSL usage - better fallback support to old RestAPI, if entertainment api is not supported - just 4 u LordGrey: new log fn for cosmetic config outputs ;) * add OSX CompileHowTo - undo from CrossCompileHowTo * whitespace fixes * lightID toString fix * fix unsigned int E-API + debug output * bugfixes, reworked black signal detection, wizard: - change device config field light-ids from int to string -> real unsigned int fix - add signal detection brightness minimum threshold value 0.0 for 0% brightness - 1.0 for 100% brightness to count for blacklight signal detection reason: input may not 100% black, like mine - i have a deep dark gray input signal -> my threshold value is set to 0.005 for 0.5% minimum brightness = 1 (from max 255) to count as black - wizard optimations, with fallback without entertainment support (beta state) - whitespace fixes * cleanup + minor fixes * change fixed Hue UPD SSL config to _devConfig paras * Hotfix SSL Connection, new light models, wizard: - Fix UPD SSL Connection failed Problems - add new supported gamut C light models: LCG002, LCA001, LCA002, LCA003 - wizard: extend fallback support to classic mode + hints * whitespace, typo fix * uncheck useEntertainmentAPI, if noAPISupport detected + hint * coredump fix -> add _blackLightsTimer nullptr init * code cleanup / remove old debugs + whitespacefixes * add gamut C LCP001, LCP002 * SSL UDP config made more flexible + remove qDebug -> switch to hyerion.ng _log -> replace logCommand with verbose -> code cleanups etc... * extended mbedtls debugging infos * add adjustable ssl timeout settings * error handling * streamdebugger bugfixes * UPDSSL psk / psk_identity bugfixes! + hue wizard fn typo fix + - verbose option available without dependencies - whitespace fixes * Philips Hue Assistant now recognizes non-original bridges better... + Added note if no clientkey is set when using the entertainment API + User creation (+ clientkey) for non-original bridges can now also be used + Minor changes and bug fixes * CMAKE mbedTLS detection * minor bug fixes + code cleanups * FindMbedTLS.cmake remove Path-Hints + wizard.js: ajax timeout handling Test - content_grabber.js: run relevant code only, if V4L2_AVAIL is true: conf_grabber don't displays other devices, if V4L2 is not available * compile mbedtls via cmake as static lib * remove libmbedtls-dev from compileHowto / scripts * Fix Windows build * Fix windows build (part 2) * removed unnecessary osx x11 include directory path * QTimer Shutdown bugfix * cmake win32 fix + minor bugfixes * cmake debug msg used mbedtls libs * Bugfix: noSignalDetection wasn't switchedOn again if no signal was previously detected * Some code fixes based on alerts from lgtm.com Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
288 lines
7.9 KiB
JavaScript
288 lines
7.9 KiB
JavaScript
/**
|
|
* jQuery Internationalization library
|
|
*
|
|
* Copyright (C) 2012 Santhosh Thottingal
|
|
*
|
|
* jquery.i18n is dual licensed GPLv2 or later and MIT. You don't have to do
|
|
* anything special to choose one license or the other and you don't have to
|
|
* notify anyone which license you are using. You are free to use
|
|
* UniversalLanguageSelector in commercial projects as long as the copyright
|
|
* header is left intact. See files GPL-LICENSE and MIT-LICENSE for details.
|
|
*
|
|
* @licence GNU General Public Licence 2.0 or later
|
|
* @licence MIT License
|
|
*/
|
|
|
|
( function ( $ ) {
|
|
'use strict';
|
|
|
|
var nav, I18N,
|
|
slice = Array.prototype.slice;
|
|
/**
|
|
* @constructor
|
|
* @param {Object} options
|
|
*/
|
|
I18N = function ( options ) {
|
|
// Load defaults
|
|
this.options = $.extend( {}, I18N.defaults, options );
|
|
|
|
this.parser = this.options.parser;
|
|
this.locale = this.options.locale;
|
|
this.messageStore = this.options.messageStore;
|
|
this.languages = {};
|
|
|
|
this.init();
|
|
};
|
|
|
|
I18N.prototype = {
|
|
/**
|
|
* Initialize by loading locales and setting up
|
|
* String.prototype.toLocaleString and String.locale.
|
|
*/
|
|
init: function () {
|
|
var i18n = this;
|
|
|
|
// Set locale of String environment
|
|
String.locale = i18n.locale;
|
|
|
|
// Override String.localeString method
|
|
String.prototype.toLocaleString = function () {
|
|
var localeParts, localePartIndex, value, locale, fallbackIndex,
|
|
tryingLocale, message;
|
|
|
|
value = this.valueOf();
|
|
locale = i18n.locale;
|
|
fallbackIndex = 0;
|
|
|
|
while ( locale ) {
|
|
// Iterate through locales starting at most-specific until
|
|
// localization is found. As in fi-Latn-FI, fi-Latn and fi.
|
|
localeParts = locale.split( '-' );
|
|
localePartIndex = localeParts.length;
|
|
|
|
do {
|
|
tryingLocale = localeParts.slice( 0, localePartIndex ).join( '-' );
|
|
message = i18n.messageStore.get( tryingLocale, value );
|
|
|
|
if ( message ) {
|
|
return message;
|
|
}
|
|
|
|
localePartIndex--;
|
|
} while ( localePartIndex );
|
|
|
|
if ( locale === 'en' ) {
|
|
break;
|
|
}
|
|
|
|
locale = ( $.i18n.fallbacks[i18n.locale] && $.i18n.fallbacks[i18n.locale][fallbackIndex] ) ||
|
|
i18n.options.fallbackLocale;
|
|
$.i18n.log( 'Trying fallback locale for ' + i18n.locale + ': ' + locale );
|
|
|
|
fallbackIndex++;
|
|
}
|
|
|
|
// key not found
|
|
return '';
|
|
};
|
|
},
|
|
|
|
/*
|
|
* Destroy the i18n instance.
|
|
*/
|
|
destroy: function () {
|
|
$.removeData( document, 'i18n' );
|
|
},
|
|
|
|
/**
|
|
* General message loading API This can take a URL string for
|
|
* the json formatted messages. Example:
|
|
* <code>load('path/to/all_localizations.json');</code>
|
|
*
|
|
* To load a localization file for a locale:
|
|
* <code>
|
|
* load('path/to/de-messages.json', 'de' );
|
|
* </code>
|
|
*
|
|
* To load a localization file from a directory:
|
|
* <code>
|
|
* load('path/to/i18n/directory', 'de' );
|
|
* </code>
|
|
* The above method has the advantage of fallback resolution.
|
|
* ie, it will automatically load the fallback locales for de.
|
|
* For most usecases, this is the recommended method.
|
|
* It is optional to have trailing slash at end.
|
|
*
|
|
* A data object containing message key- message translation mappings
|
|
* can also be passed. Example:
|
|
* <code>
|
|
* load( { 'hello' : 'Hello' }, optionalLocale );
|
|
* </code>
|
|
*
|
|
* A source map containing key-value pair of languagename and locations
|
|
* can also be passed. Example:
|
|
* <code>
|
|
* load( {
|
|
* bn: 'i18n/bn.json',
|
|
* he: 'i18n/he.json',
|
|
* en: 'i18n/en.json'
|
|
* } )
|
|
* </code>
|
|
*
|
|
* If the data argument is null/undefined/false,
|
|
* all cached messages for the i18n instance will get reset.
|
|
*
|
|
* @param {String|Object} source
|
|
* @param {String} locale Language tag
|
|
* @returns {jQuery.Promise}
|
|
*/
|
|
load: function ( source, locale ) {
|
|
var fallbackLocales, locIndex, fallbackLocale, sourceMap = {};
|
|
if ( !source && !locale ) {
|
|
source = 'i18n';
|
|
locale = $.i18n().locale;
|
|
}
|
|
if ( typeof source === 'string' &&
|
|
source.split( '.' ).pop() !== 'json'
|
|
) {
|
|
// Load specified locale then check for fallbacks when directory is specified in load()
|
|
sourceMap[locale] = source + '/' + locale + '.json';
|
|
fallbackLocales = ( $.i18n.fallbacks[locale] || [] )
|
|
.concat( this.options.fallbackLocale );
|
|
for ( locIndex in fallbackLocales ) {
|
|
fallbackLocale = fallbackLocales[locIndex];
|
|
sourceMap[fallbackLocale] = source + '/' + fallbackLocale + '.json';
|
|
}
|
|
return this.load( sourceMap );
|
|
} else {
|
|
return this.messageStore.load( source, locale );
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
* Does parameter and magic word substitution.
|
|
*
|
|
* @param {string} key Message key
|
|
* @param {Array} parameters Message parameters
|
|
* @return {string}
|
|
*/
|
|
parse: function ( key, parameters ) {
|
|
var message = key.toLocaleString();
|
|
// FIXME: This changes the state of the I18N object,
|
|
// should probably not change the 'this.parser' but just
|
|
// pass it to the parser.
|
|
this.parser.language = $.i18n.languages[$.i18n().locale] || $.i18n.languages['default'];
|
|
if ( message === '' ) {
|
|
message = key;
|
|
}
|
|
return this.parser.parse( message, parameters );
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Process a message from the $.I18N instance
|
|
* for the current document, stored in jQuery.data(document).
|
|
*
|
|
* @param {string} key Key of the message.
|
|
* @param {string} param1 [param...] Variadic list of parameters for {key}.
|
|
* @return {string|$.I18N} Parsed message, or if no key was given
|
|
* the instance of $.I18N is returned.
|
|
*/
|
|
$.i18n = function ( key, param1 ) {
|
|
var parameters,
|
|
i18n = $.data( document, 'i18n' ),
|
|
options = typeof key === 'object' && key;
|
|
|
|
// If the locale option for this call is different then the setup so far,
|
|
// update it automatically. This doesn't just change the context for this
|
|
// call but for all future call as well.
|
|
// If there is no i18n setup yet, don't do this. It will be taken care of
|
|
// by the `new I18N` construction below.
|
|
// NOTE: It should only change language for this one call.
|
|
// Then cache instances of I18N somewhere.
|
|
if ( options && options.locale && i18n && i18n.locale !== options.locale ) {
|
|
String.locale = i18n.locale = options.locale;
|
|
}
|
|
|
|
if ( !i18n ) {
|
|
i18n = new I18N( options );
|
|
$.data( document, 'i18n', i18n );
|
|
}
|
|
|
|
if ( typeof key === 'string' ) {
|
|
if ( param1 !== undefined ) {
|
|
parameters = slice.call( arguments, 1 );
|
|
} else {
|
|
parameters = [];
|
|
}
|
|
|
|
return i18n.parse( key, parameters );
|
|
} else {
|
|
// FIXME: remove this feature/bug.
|
|
return i18n;
|
|
}
|
|
};
|
|
|
|
$.fn.i18n = function () {
|
|
var i18n = $.data( document, 'i18n' );
|
|
|
|
if ( !i18n ) {
|
|
i18n = new I18N();
|
|
$.data( document, 'i18n', i18n );
|
|
}
|
|
String.locale = i18n.locale;
|
|
return this.each( function () {
|
|
var $this = $( this ),
|
|
messageKey = $this.data( 'i18n' );
|
|
|
|
if ( messageKey ) {
|
|
$this.text( i18n.parse( messageKey ) );
|
|
} else {
|
|
$this.find( '[data-i18n]' ).i18n();
|
|
}
|
|
} );
|
|
};
|
|
|
|
String.locale = String.locale || $( 'html' ).attr( 'lang' );
|
|
|
|
if ( !String.locale ) {
|
|
if ( typeof window.navigator !== 'undefined' ) {
|
|
nav = window.navigator;
|
|
String.locale = nav.language || nav.userLanguage || '';
|
|
} else {
|
|
String.locale = '';
|
|
}
|
|
}
|
|
|
|
$.i18n.languages = {};
|
|
$.i18n.messageStore = $.i18n.messageStore || {};
|
|
$.i18n.parser = {
|
|
// The default parser only handles variable substitution
|
|
parse: function ( message, parameters ) {
|
|
return message.replace( /\$(\d+)/g, function ( str, match ) {
|
|
var index = parseInt( match, 10 ) - 1;
|
|
return parameters[index] !== undefined ? parameters[index] : '$' + match;
|
|
} );
|
|
},
|
|
emitter: {}
|
|
};
|
|
$.i18n.fallbacks = {};
|
|
$.i18n.debug = false;
|
|
$.i18n.log = function ( /* arguments */ ) {
|
|
if ( window.console && $.i18n.debug ) {
|
|
window.console.log.apply( window.console, arguments );
|
|
}
|
|
};
|
|
/* Static members */
|
|
I18N.defaults = {
|
|
locale: String.locale,
|
|
fallbackLocale: 'en',
|
|
parser: $.i18n.parser,
|
|
messageStore: $.i18n.messageStore
|
|
};
|
|
|
|
// Expose constructor
|
|
$.i18n.constructor = I18N;
|
|
}( jQuery ) );
|