Skip to content

Commit 452c392

Browse files
committed
deprecate Ember.String.loc and {{loc}}
1 parent f2104f2 commit 452c392

File tree

4 files changed

+81
-39
lines changed

4 files changed

+81
-39
lines changed

packages/@ember/-internals/glimmer/lib/helpers/loc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { helper } from '../helper';
3636
@param {String} str The string to format.
3737
@see {String#loc}
3838
@public
39+
@deprecated
3940
*/
4041
export default helper(function (params) {
4142
return loc.apply(null, params as any /* let the other side handle errors */);

packages/@ember/-internals/glimmer/tests/integration/helpers/loc-test.js

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,53 +20,69 @@ moduleFor(
2020
}
2121

2222
['@test it lets the original value through by default']() {
23-
this.render(`{{loc "Hiya buddy!"}}`);
23+
expectDeprecation(() => this.render(`{{loc "Hiya buddy!"}}`), /loc is deprecated/);
2424
this.assertText('Hiya buddy!', 'the unlocalized string is correct');
2525
runTask(() => this.rerender());
2626
this.assertText('Hiya buddy!', 'the unlocalized string is correct after rerender');
2727
}
2828

2929
['@test it localizes a simple string']() {
30-
this.render(`{{loc "Hello Friend"}}`);
30+
expectDeprecation(() => this.render(`{{loc "Hello Friend"}}`), /loc is deprecated/);
3131
this.assertText('Hallo Freund', 'the localized string is correct');
3232
runTask(() => this.rerender());
3333
this.assertText('Hallo Freund', 'the localized string is correct after rerender');
3434
}
3535

3636
['@test it takes passed formats into an account']() {
37-
this.render(`{{loc "%@, %@" "Hello" "Mr. Pitkin"}}`);
37+
expectDeprecation(() => {
38+
this.render(`{{loc "%@, %@" "Hello" "Mr. Pitkin"}}`);
39+
}, /loc is deprecated/);
3840
this.assertText('Hello, Mr. Pitkin', 'the formatted string is correct');
3941
runTask(() => this.rerender());
4042
this.assertText('Hello, Mr. Pitkin', 'the formatted string is correct after rerender');
4143
}
4244

4345
['@test it updates when bound params change']() {
44-
this.render(`{{loc simple}} - {{loc personal 'Mr. Pitkin'}}`, {
45-
simple: 'Hello Friend',
46-
personal: 'Hello',
47-
});
48-
this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct');
46+
expectDeprecation(() => {
47+
this.render(`{{loc simple}} - {{loc personal 'Mr. Pitkin'}}`, {
48+
simple: 'Hello Friend',
49+
personal: 'Hello',
50+
});
51+
this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct');
52+
}, /loc is deprecated/);
4953

5054
runTask(() => this.rerender());
5155
this.assertText(
5256
'Hallo Freund - Hallo, Mr. Pitkin',
5357
'the bound value is correct after rerender'
5458
);
5559

56-
runTask(() => set(this.context, 'simple', "G'day mate"));
57-
this.assertText("G'day mate - Hallo, Mr. Pitkin", 'the bound value is correct after update');
60+
expectDeprecation(() => {
61+
runTask(() => set(this.context, 'simple', "G'day mate"));
62+
this.assertText(
63+
"G'day mate - Hallo, Mr. Pitkin",
64+
'the bound value is correct after update'
65+
);
66+
}, /loc is deprecated/);
5867

59-
runTask(() => set(this.context, 'simple', 'Hello Friend'));
60-
this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct after reset');
68+
expectDeprecation(() => {
69+
runTask(() => set(this.context, 'simple', 'Hello Friend'));
70+
this.assertText(
71+
'Hallo Freund - Hallo, Mr. Pitkin',
72+
'the bound value is correct after reset'
73+
);
74+
}, /loc is deprecated/);
6175
}
6276

6377
['@test it updates when nested bound params change']() {
64-
this.render(`{{loc greetings.simple}} - {{loc greetings.personal 'Mr. Pitkin'}}`, {
65-
greetings: {
66-
simple: 'Hello Friend',
67-
personal: 'Hello',
68-
},
69-
});
78+
expectDeprecation(() => {
79+
this.render(`{{loc greetings.simple}} - {{loc greetings.personal 'Mr. Pitkin'}}`, {
80+
greetings: {
81+
simple: 'Hello Friend',
82+
personal: 'Hello',
83+
},
84+
});
85+
}, /loc is deprecated/);
7086
this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct');
7187

7288
runTask(() => this.rerender());
@@ -75,22 +91,26 @@ moduleFor(
7591
'the bound value is correct after rerender'
7692
);
7793

78-
runTask(() => set(this.context, 'greetings.simple', "G'day mate"));
79-
this.assertText(
80-
"G'day mate - Hallo, Mr. Pitkin",
81-
'the bound value is correct after interior mutation'
82-
);
94+
expectDeprecation(() => {
95+
runTask(() => set(this.context, 'greetings.simple', "G'day mate"));
96+
this.assertText(
97+
"G'day mate - Hallo, Mr. Pitkin",
98+
'the bound value is correct after interior mutation'
99+
);
100+
}, /loc is deprecated/);
83101

84-
runTask(() =>
85-
set(this.context, 'greetings', {
86-
simple: 'Hello Friend',
87-
personal: 'Hello',
88-
})
89-
);
90-
this.assertText(
91-
'Hallo Freund - Hallo, Mr. Pitkin',
92-
'the bound value is correct after replacement'
93-
);
102+
expectDeprecation(() => {
103+
runTask(() =>
104+
set(this.context, 'greetings', {
105+
simple: 'Hello Friend',
106+
personal: 'Hello',
107+
})
108+
);
109+
this.assertText(
110+
'Hallo Freund - Hallo, Mr. Pitkin',
111+
'the bound value is correct after replacement'
112+
);
113+
}, /loc is deprecated/);
94114
}
95115

96116
['@test it can be overriden']() {

packages/@ember/string/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export { getStrings as _getStrings, setStrings as _setStrings } from './lib/stri
66

77
import { ENV } from '@ember/-internals/environment';
88
import { Cache } from '@ember/-internals/utils';
9+
import { deprecate } from '@ember/debug';
910
import { getString } from './lib/string_registry';
1011

1112
const STRING_DASHERIZE_REGEXP = /[ _]/g;
@@ -109,8 +110,23 @@ function _fmt(str: string, formats: any[]) {
109110
@param {Array} formats Optional array of parameters to interpolate into string.
110111
@return {String} formatted string
111112
@public
113+
@deprecated
112114
*/
113115
export function loc(str: string, formats: any[]): string {
116+
deprecate(
117+
'loc is deprecated, please use a dedicated localization solution like ember-intl. More alternatives listed at https://emberobserver.com/categories/internationalization.',
118+
false,
119+
{
120+
id: 'ember-string.loc',
121+
until: '4.0.0',
122+
for: 'ember-source',
123+
url: 'https://deprecations.emberjs.com/v3.x#toc_ember-string-loc',
124+
since: {
125+
available: '3.24',
126+
},
127+
}
128+
);
129+
114130
if (!Array.isArray(formats) || arguments.length > 2) {
115131
formats = Array.prototype.slice.call(arguments, 1);
116132
}
@@ -304,6 +320,7 @@ if (ENV.EXTEND_PROTOTYPES.String) {
304320
@for @ember/string
305321
@static
306322
@private
323+
@deprecated
307324
*/
308325
loc: {
309326
configurable: true,

packages/@ember/string/tests/loc_test.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
66
let oldString;
77

88
function test(assert, given, args, expected, description) {
9-
assert.equal(loc(given, args), expected, description);
10-
if (ENV.EXTEND_PROTOTYPES.String) {
11-
assert.deepEqual(given.loc(...args), expected, description);
12-
}
9+
expectDeprecation(() => {
10+
assert.equal(loc(given, args), expected, description);
11+
if (ENV.EXTEND_PROTOTYPES.String) {
12+
assert.deepEqual(given.loc(...args), expected, description);
13+
}
14+
}, /loc is deprecated/);
1315
}
1416

1517
moduleFor(
@@ -69,8 +71,10 @@ moduleFor(
6971
}
7072

7173
['@test works with argument form'](assert) {
72-
assert.equal(loc('_Hello %@', 'John'), 'Bonjour John');
73-
assert.equal(loc('_Hello %@ %@', ['John'], 'Doe'), 'Bonjour John Doe');
74+
expectDeprecation(() => {
75+
assert.equal(loc('_Hello %@', 'John'), 'Bonjour John');
76+
assert.equal(loc('_Hello %@ %@', ['John'], 'Doe'), 'Bonjour John Doe');
77+
}, /loc is deprecated/);
7478
}
7579
}
7680
);

0 commit comments

Comments
 (0)