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
This commit is contained in:
Travis Tripp 2015-08-26 04:26:15 -06:00
parent 16e0d7c1c3
commit eabc23c3b8
5 changed files with 56 additions and 13 deletions

View File

@ -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;

View File

@ -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_) {

View File

@ -82,13 +82,13 @@
</dl>
<dl class="col-sm-2">
<dt translate>Project ID</dt>
<dd>{$ user.tenantId || user.default_project_id || '-'$}</dd>
<dd>{$ user.tenantId || user.default_project_id | noValue $}</dd>
</dl>
<span class="rsp-alt-p2">
<dl class="col-sm-2">
<dt translate>Email</dt>
<dd>{$ user.email || '-' $}</dd>
<dd>{$ user.email | noValue $}</dd>
</dl>
<dl class="col-sm-2">
<dt translate>Enabled</dt>

View File

@ -10,11 +10,11 @@
</tr>
</thead>
<tr ng-repeat="d in row.security_group_rules">
<td>{$ d.direction || '-' $}</td>
<td>{$ d.ethertype || '-' $}</td>
<td>{$ d.protocol || '-' $}</td>
<td>{$ d.port_range_min || '-' $}</td>
<td>{$ d.port_range_max || '-' $}</td>
<td>{$ d.remote_ip_prefix || '-' $}</td>
<td>{$ d.direction | noValue $}</td>
<td>{$ d.ethertype | noValue $}</td>
<td>{$ d.protocol | noValue $}</td>
<td>{$ d.port_range_min | noValue $}</td>
<td>{$ d.port_range_max | noValue $}</td>
<td>{$ d.remote_ip_prefix | noValue $}</td>
</tr>
</table>

View File

@ -70,7 +70,7 @@
<td class="rsp-p1">{$ image.status | imageStatus $}</td>
<td class="rsp-p2">{$ image.is_public | yesno $}</td>
<td class="rsp-p2">{$ image.protected | yesno $}</td>
<td class="rsp-p2">{$ image.disk_format || '-' $}</td>
<td class="rsp-p2">{$ image.disk_format | noValue | uppercase $}</td>
<td class="rsp-p2">{$ image.size | bytes $}</td>
</tr>
@ -99,7 +99,7 @@
</dl>
<dl class="col-sm-2">
<dt translate>Format</dt>
<dd>{$ image.disk_format || '-' $}</dd>
<dd>{$ image.disk_format | noValue $}</dd>
</dl>
<dl class="col-sm-2">
<dt translate>Size</dt>
@ -111,11 +111,11 @@
<div class="row">
<dl class="col-sm-2">
<dt translate>Min Disk (GB)</dt>
<dd>{$ image.min_disk || '-' $}</dd>
<dd>{$ image.min_disk | noValue $}</dd>
</dl>
<dl class="col-sm-2">
<dt translate>Min RAM (MB)</dt>
<dd>{$ image.min_ram || '-' $}</dd>
<dd>{$ image.min_ram | noValue $}</dd>
</dl>
</div>