Update to 2.4.1

Change-Id: Iae603434f1897fcbf47cf37bbedf5956848a5bd2
This commit is contained in:
Radomir Dopieralski 2020-01-21 13:51:01 +01:00
parent 9c8b0dd8e7
commit 6b7ba0f82b
4 changed files with 27 additions and 20 deletions

View File

@ -1,5 +1,5 @@
XStatic-Angular-Gettext XStatic-Angular-Gettext
-------------- -----------------------
Angular-Gettext javascript library packaged for setuptools (easy_install) / pip. Angular-Gettext javascript library packaged for setuptools (easy_install) / pip.

View File

@ -1,9 +1,9 @@
[metadata] [metadata]
name = XStatic-Angular-Gettext name = XStatic-Angular-Gettext
description = Angular-Gettext 2.3.8 (XStatic packaging standard) description = Angular-Gettext 2.4.1 (XStatic packaging standard)
description-file = README.rst description-file = README.rst
maintainer = Rob Cresswell maintainer = Radomir Dopieralski
maintainer-email = robert.cresswell@outlook.com maintainer-email = openstack@sheep.art.pl
home-page = https://angular-gettext.rocketeer.be/ home-page = https://angular-gettext.rocketeer.be/
keywords = angular_gettext xstatic keywords = angular_gettext xstatic
license = MIT license = MIT

View File

@ -11,7 +11,7 @@ NAME = __name__.split('.')[-1] # package name (e.g. 'foo' or 'foo_bar')
# please use a all-lowercase valid python # please use a all-lowercase valid python
# package name # package name
VERSION = '2.3.8' # version of the packaged files, please use the upstream VERSION = '2.4.1' # version of the packaged files, please use the upstream
# version number # version number
BUILD = '0' # our package build number, so we can release new builds BUILD = '0' # our package build number, so we can release new builds
# with fixes for xstatic stuff. # with fixes for xstatic stuff.
@ -24,8 +24,8 @@ CLASSIFIERS = []
KEYWORDS = '%s xstatic' % NAME KEYWORDS = '%s xstatic' % NAME
# XStatic-* package maintainer: # XStatic-* package maintainer:
MAINTAINER = 'Rob Cresswell' MAINTAINER = 'Radomir Dopieralski'
MAINTAINER_EMAIL = 'robert.cresswell@outlook.com' MAINTAINER_EMAIL = 'openstack@sheep.art.pl'
# this refers to the project homepage of the stuff we packaged: # this refers to the project homepage of the stuff we packaged:
HOMEPAGE = 'https://angular-gettext.rocketeer.be/' HOMEPAGE = 'https://angular-gettext.rocketeer.be/'

View File

@ -60,7 +60,7 @@ angular.module('gettext').constant('gettext', function (str) {
* @requires https://docs.angularjs.org/api/ng/service/$cacheFactory $cacheFactory * @requires https://docs.angularjs.org/api/ng/service/$cacheFactory $cacheFactory
* @requires https://docs.angularjs.org/api/ng/service/$interpolate $interpolate * @requires https://docs.angularjs.org/api/ng/service/$interpolate $interpolate
* @requires https://docs.angularjs.org/api/ng/service/$rootScope $rootScope * @requires https://docs.angularjs.org/api/ng/service/$rootScope $rootScope
* @description Provides set of method to translate stings * @description Provides set of method to translate strings
*/ */
angular.module('gettext').factory('gettextCatalog', ["gettextPlurals", "gettextFallbackLanguage", "$http", "$cacheFactory", "$interpolate", "$rootScope", function (gettextPlurals, gettextFallbackLanguage, $http, $cacheFactory, $interpolate, $rootScope) { angular.module('gettext').factory('gettextCatalog', ["gettextPlurals", "gettextFallbackLanguage", "$http", "$cacheFactory", "$interpolate", "$rootScope", function (gettextPlurals, gettextFallbackLanguage, $http, $cacheFactory, $interpolate, $rootScope) {
var catalog; var catalog;
@ -233,15 +233,20 @@ angular.module('gettext').factory('gettextCatalog', ["gettextPlurals", "gettextF
val = obj; val = obj;
} }
// Expand single strings for each context. if (!this.strings[language][key]) {
this.strings[language][key] = {};
}
for (var context in val) { for (var context in val) {
var str = val[context]; var str = val[context];
if (!angular.isArray(str)) { if (!angular.isArray(str)) {
val[context] = []; // Expand single strings
val[context][defaultPlural] = str; this.strings[language][key][context] = [];
this.strings[language][key][context][defaultPlural] = str;
} else {
this.strings[language][key][context] = str;
} }
} }
this.strings[language][key] = val;
} }
broadcastUpdated(); broadcastUpdated();
@ -253,7 +258,7 @@ angular.module('gettext').factory('gettextCatalog', ["gettextPlurals", "gettextF
* @protected * @protected
* @param {String} language language name * @param {String} language language name
* @param {String} string translation key * @param {String} string translation key
* @param {Number=} n number to build sting form for * @param {Number=} n number to build string form for
* @param {String=} context translation key context, e.g. {@link doc:context Verb, Noun} * @param {String=} context translation key context, e.g. {@link doc:context Verb, Noun}
* @returns {String|Null} translated or annotated string or null if language is not set * @returns {String|Null} translated or annotated string or null if language is not set
* @description Translate a string with the given language, count and context. * @description Translate a string with the given language, count and context.
@ -300,7 +305,7 @@ angular.module('gettext').factory('gettextCatalog', ["gettextPlurals", "gettextF
* @ngdoc method * @ngdoc method
* @name gettextCatalog#getPlural * @name gettextCatalog#getPlural
* @public * @public
* @param {Number} n number to build sting form for * @param {Number} n number to build string form for
* @param {String} string translation key * @param {String} string translation key
* @param {String} stringPlural plural translation key * @param {String} stringPlural plural translation key
* @param {$rootScope.Scope=} scope scope to do interpolation against * @param {$rootScope.Scope=} scope scope to do interpolation against
@ -405,7 +410,7 @@ angular.module('gettext').factory('gettextCatalog', ["gettextPlurals", "gettextF
* ``` * ```
*/ */
angular.module('gettext').directive('translate', ["gettextCatalog", "$parse", "$animate", "$compile", "$window", "gettextUtil", function (gettextCatalog, $parse, $animate, $compile, $window, gettextUtil) { angular.module('gettext').directive('translate', ["gettextCatalog", "$parse", "$animate", "$compile", "$window", "gettextUtil", function (gettextCatalog, $parse, $animate, $compile, $window, gettextUtil) {
var msie = parseInt((/msie (\d+)/.exec(angular.lowercase($window.navigator.userAgent)) || [])[1], 10); var msie = parseInt((/msie (\d+)/i.exec($window.navigator.userAgent) || [])[1], 10);
var PARAMS_PREFIX = 'translateParams'; var PARAMS_PREFIX = 'translateParams';
function getCtxAttr(key) { function getCtxAttr(key) {
@ -421,7 +426,7 @@ angular.module('gettext').directive('translate', ["gettextCatalog", "$parse", "$
return null; return null;
} }
var interpolationContext = angular.extend({}, scope); var interpolationContext = scope.$new();
var unwatchers = []; var unwatchers = [];
attributes.forEach(function (attribute) { attributes.forEach(function (attribute) {
var unwatch = scope.$watch(attrs[attribute], function (newVal) { var unwatch = scope.$watch(attrs[attribute], function (newVal) {
@ -435,6 +440,8 @@ angular.module('gettext').directive('translate', ["gettextCatalog", "$parse", "$
unwatchers.forEach(function (unwatch) { unwatchers.forEach(function (unwatch) {
unwatch(); unwatch();
}); });
interpolationContext.$destroy();
}); });
return interpolationContext; return interpolationContext;
} }
@ -473,13 +480,13 @@ angular.module('gettext').directive('translate', ["gettextCatalog", "$parse", "$
if (translatePlural) { if (translatePlural) {
scope = pluralScope || (pluralScope = scope.$new()); scope = pluralScope || (pluralScope = scope.$new());
scope.$count = countFn(scope); scope.$count = countFn(scope);
translated = gettextCatalog.getPlural(scope.$count, msgid, translatePlural, interpolationContext, translateContext); translated = gettextCatalog.getPlural(scope.$count, msgid, translatePlural, null, translateContext);
} else { } else {
translated = gettextCatalog.getString(msgid, interpolationContext, translateContext); translated = gettextCatalog.getString(msgid, null, translateContext);
} }
var oldContents = element.contents(); var oldContents = element.contents();
if (oldContents.length === 0){ if (!oldContents && !translated){
return; return;
} }
@ -494,7 +501,7 @@ angular.module('gettext').directive('translate', ["gettextCatalog", "$parse", "$
// Swap in the translation // Swap in the translation
var newWrapper = angular.element('<span>' + translated + '</span>'); var newWrapper = angular.element('<span>' + translated + '</span>');
$compile(newWrapper.contents())(scope); $compile(newWrapper.contents())(interpolationContext || scope);
var newContents = newWrapper.contents(); var newContents = newWrapper.contents();
$animate.enter(newContents, element); $animate.enter(newContents, element);