Merge pull request #1971 from agrajaghh/upstream_angular_gettext

remove localize filter, put args filter in Localization.js
This commit is contained in:
Kenneth Skovhede
2016-10-03 10:57:08 +02:00
committed by GitHub
5 changed files with 18 additions and 62 deletions
-1
View File
@@ -89,7 +89,6 @@
<script type="text/javascript" src="scripts/controllers/LocalDatabaseController.js"></script>
<script type="text/javascript" src="scripts/filters/args.js"></script>
<script type="text/javascript" src="scripts/filters/localize.js"></script>
<script type="text/javascript" src="scripts/filters/timeremaining.js"></script>
<script type="text/javascript" src="scripts/filters/highlight.js"></script>
<script type="text/javascript" src="scripts/filters/parsetimestamp.js"></script>
@@ -1,34 +1,5 @@
backupApp.filter('args', function() {
backupApp.filter('args', function(Localization) {
return function() {
this.preg_quote = function preg_quote (str, delimiter) {
// discuss at: http://locutus.io/php/preg_quote/
// original by: booeyOH
// improved by: Ates Goral (http://magnetiq.com)
// improved by: Kevin van Zonneveld (http://kvz.io)
// improved by: Brett Zamir (http://brett-zamir.me)
// bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)
// example 1: preg_quote("$40")
// returns 1: '\\$40'
// example 2: preg_quote("*RRRING* Hello?")
// returns 2: '\\*RRRING\\* Hello\\?'
// example 3: preg_quote("\\.+*?[^]$(){}=!<>|:")
// returns 3: '\\\\\\.\\+\\*\\?\\[\\^\\]\\$\\(\\)\\{\\}\\=\\!\\<\\>\\|\\:'
return (str + '')
.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&')
}
if (arguments == null || arguments.length < 1)
return null;
if (arguments.length == 1)
return arguments[0];
var msg = arguments[0];
for (var i = 1; i < arguments.length; i++)
msg = msg.replace(new RegExp( "(" + this.preg_quote('{' + (i-1) + '}') + ")" , 'g' ), arguments[i]);
return msg;
return Localization.format.apply(Localization, arguments);
}
});
@@ -1,5 +0,0 @@
backupApp.filter('localize', function(Localization) {
return function() {
return Localization.localize.apply(Localization, arguments);
}
});
@@ -3,21 +3,22 @@ backupApp.service('Localization', function($rootScope, $timeout, AppService) {
var self = this;
this.preg_quote = function( str ) {
// http://kevin.vanzonneveld.net
// + original by: booeyOH
// + improved by: Ates Goral (http://magnetiq.com)
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: Onno Marsman
// * example 1: preg_quote("$40");
// * returns 1: '\$40'
// * example 2: preg_quote("*RRRING* Hello?");
// * returns 2: '\*RRRING\* Hello\?'
// * example 3: preg_quote("\\.+*?[^]$(){}=!<>|:");
// * returns 3: '\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:'
this.preg_quote = function preg_quote (str, delimiter) {
// discuss at: http://locutus.io/php/preg_quote/
// original by: booeyOH
// improved by: Ates Goral (http://magnetiq.com)
// improved by: Kevin van Zonneveld (http://kvz.io)
// improved by: Brett Zamir (http://brett-zamir.me)
// bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)
// example 1: preg_quote("$40")
// returns 1: '\\$40'
// example 2: preg_quote("*RRRING* Hello?")
// returns 2: '\\*RRRING\\* Hello\\?'
// example 3: preg_quote("\\.+*?[^]$(){}=!<>|:")
// returns 3: '\\\\\\.\\+\\*\\?\\[\\^\\]\\$\\(\\)\\{\\}\\=\\!\\<\\>\\|\\:'
return (str+'').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1");
}
return (str + '').replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&')
};
this.format = function() {
if (arguments == null || arguments.length < 1)
@@ -34,16 +35,6 @@ backupApp.service('Localization', function($rootScope, $timeout, AppService) {
return msg;
};
this.localize = function() {
if (arguments == null || arguments.length < 1)
return '';
if (this.strings[arguments[0]] != null)
arguments[0] = this.strings[arguments[0]];
return this.format.apply(this, arguments);
};
this.watch = function(scope, m) {
scope.$on('localizationchanged', function() {
if (m) m();
@@ -68,7 +68,7 @@
<div class="input checkbox">
<input type="radio" class="checkbox" id="updateChannelBeta" value="beta" name="updateChannel" ng-model="updateChannel" />
<label for="updateChannelBeta" translate>Beta</label>
<div class="sublabel" translate>Try out the new features we are working on. Don\'t use with important data.</div>
<div class="sublabel" translate>Try out the new features we are working on. Don't use with important data.</div>
</div>
<div class="input checkbox">
<input type="radio" class="checkbox" id="updateChannelExperimental" value="experimental" name="updateChannel" ng-model="updateChannel" />