From eabc23c3b85b2612ac43bf17785d848c90621382 Mon Sep 17 00:00:00 2001 From: Travis Tripp Date: Wed, 26 Aug 2015 04:26:15 -0600 Subject: [PATCH] Translate angular html with '-'. The empty value of '-' needs to be translated. This adds the translation for it with a new filter. To test: In local_settings.py LAUNCH_INSTANCE_NG_ENABLED = True update enabled/_1051_project_ng_images_panel.py update enabled/_3031_identity_users_panel.py set disabled=False Then: ./run_tests.sh --makemessages ./run_tests.sh --pseudo de ./run_tests.sh --compilemessages ./run_tests.sh --runserver 0.0.0.0:8005 Go to: http://localhost:8005/settings/ Change Language to Deutsch (de) Go to: http://localhost:8005/project/ngimages/ http://localhost:8005/project/ngusers/ Launch an instance. Go to security groups step. Expand details for a security group. All text on page should be fake localized where the english is surrounded by other characters. [~-~KanjiChars] Change-Id: Ic004732a970d0af857534a1b3d367732be370979 Closes-Bug: #1496679 --- .../static/framework/util/filters/filters.js | 20 ++++++++++++++- .../framework/util/filters/filters.spec.js | 25 +++++++++++++++++++ .../dashboard/identity/users/table/table.html | 4 +-- .../security-group-details.html | 12 ++++----- .../app/core/images/table/images-table.html | 8 +++--- 5 files changed, 56 insertions(+), 13 deletions(-) diff --git a/horizon/static/framework/util/filters/filters.js b/horizon/static/framework/util/filters/filters.js index eb2332470c..8e90f12543 100644 --- a/horizon/static/framework/util/filters/filters.js +++ b/horizon/static/framework/util/filters/filters.js @@ -23,6 +23,7 @@ .filter('mb', mbFilter) .filter('title', titleFilter) .filter('noUnderscore', noUnderscoreFilter) + .filter('noValue', noValueFilter) .filter('decode', decodeFilter) .filter('bytes', bytesFilter) .filter('itemCount', itemCountFilter); @@ -107,6 +108,23 @@ }; } + /** + * @ngdoc filter + * @name noValue + * @description + * Replaces null / undefined / empty string with translated '-'. + */ + function noValueFilter() { + return function (input) { + if (input === null || angular.isUndefined(input) || + (angular.isString(input) && '' == input.trim())) { + return gettext('-'); + } else { + return input; + } + }; + } + /** * @ngdoc filter * @name decode @@ -161,7 +179,7 @@ */ function itemCountFilter() { - function ensureNonNegative (input) { + function ensureNonNegative(input) { var isNumeric = (input !== null && isFinite(input)); var number = isNumeric ? Math.round(input) : 0; return (number > 0) ? number : 0; diff --git a/horizon/static/framework/util/filters/filters.spec.js b/horizon/static/framework/util/filters/filters.spec.js index e6fa1931dc..7d228c68f6 100644 --- a/horizon/static/framework/util/filters/filters.spec.js +++ b/horizon/static/framework/util/filters/filters.spec.js @@ -127,6 +127,31 @@ }); }); + describe('noValue', function () { + var noValueFilter; + beforeEach(inject(function (_noValueFilter_) { + noValueFilter = _noValueFilter_; + })); + + it('returns value if there is a value', function () { + expect(noValueFilter('foo')).toBe('foo'); + expect(noValueFilter(' foo ')).toBe(' foo '); + expect(noValueFilter(true)).toBe(true); + expect(noValueFilter(false)).toBe(false); + var object = {}; + expect(noValueFilter(object)).toBe(object); + var array = []; + expect(noValueFilter(array)).toBe(array); + }); + + it('replaces undefined, null, blank with -', function () { + expect(noValueFilter(null)).toBe('-'); + expect(noValueFilter()).toBe('-'); + expect(noValueFilter('')).toBe('-'); + expect(noValueFilter(' ')).toBe('-'); + }); + }); + describe("decode", function () { var decodeFilter; beforeEach(inject(function (_decodeFilter_) { diff --git a/openstack_dashboard/dashboards/identity/static/dashboard/identity/users/table/table.html b/openstack_dashboard/dashboards/identity/static/dashboard/identity/users/table/table.html index cf47743156..fcd465eb9c 100644 --- a/openstack_dashboard/dashboards/identity/static/dashboard/identity/users/table/table.html +++ b/openstack_dashboard/dashboards/identity/static/dashboard/identity/users/table/table.html @@ -82,13 +82,13 @@
Project ID
-
{$ user.tenantId || user.default_project_id || '-'$}
+
{$ user.tenantId || user.default_project_id | noValue $}
Email
-
{$ user.email || '-' $}
+
{$ user.email | noValue $}
Enabled
diff --git a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/security-groups/security-group-details.html b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/security-groups/security-group-details.html index c76f11b2d1..bcab283b61 100644 --- a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/security-groups/security-group-details.html +++ b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/security-groups/security-group-details.html @@ -10,11 +10,11 @@ - {$ d.direction || '-' $} - {$ d.ethertype || '-' $} - {$ d.protocol || '-' $} - {$ d.port_range_min || '-' $} - {$ d.port_range_max || '-' $} - {$ d.remote_ip_prefix || '-' $} + {$ d.direction | noValue $} + {$ d.ethertype | noValue $} + {$ d.protocol | noValue $} + {$ d.port_range_min | noValue $} + {$ d.port_range_max | noValue $} + {$ d.remote_ip_prefix | noValue $} diff --git a/openstack_dashboard/static/app/core/images/table/images-table.html b/openstack_dashboard/static/app/core/images/table/images-table.html index 61c9db8766..4684d38457 100644 --- a/openstack_dashboard/static/app/core/images/table/images-table.html +++ b/openstack_dashboard/static/app/core/images/table/images-table.html @@ -70,7 +70,7 @@ {$ image.status | imageStatus $} {$ image.is_public | yesno $} {$ image.protected | yesno $} - {$ image.disk_format || '-' $} + {$ image.disk_format | noValue | uppercase $} {$ image.size | bytes $} @@ -99,7 +99,7 @@
Format
-
{$ image.disk_format || '-' $}
+
{$ image.disk_format | noValue $}
Size
@@ -111,11 +111,11 @@
Min Disk (GB)
-
{$ image.min_disk || '-' $}
+
{$ image.min_disk | noValue $}
Min RAM (MB)
-
{$ image.min_ram || '-' $}
+
{$ image.min_ram | noValue $}