Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/ember-glimmer/lib/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import {
} from './helpers/if-unless';

import { default as hash } from './helpers/hash';
import { default as loc } from './helpers/loc';

const builtInHelpers = {
concat,
if: inlineIf,
unless: inlineUnless,
hash
hash,
loc
};

export default class extends Environment {
Expand Down
45 changes: 45 additions & 0 deletions packages/ember-glimmer/lib/helpers/loc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { helper } from '../helper';
import { loc } from 'ember-runtime/system/string';

/**
@module ember
@submodule ember-templates
*/

/**
Calls [Ember.String.loc](/api/classes/Ember.String.html#method_loc) with the
provided string. This is a convenient way to localize text within a template.
For example:

```javascript
Ember.STRINGS = {
'_welcome_': 'Bonjour'
};
```

```handlebars
<div class='message'>
{{loc '_welcome_'}}
</div>
```

```html
<div class='message'>
Bonjour
</div>
```

See [Ember.String.loc](/api/classes/Ember.String.html#method_loc) for how to
set up localized string references.

@method loc
@for Ember.Templates.helpers
@param {String} str The string to format.
@see {Ember.String#loc}
@public
*/
function locHelper(params) {
return loc.apply(null, params);
}

export default helper(locHelper);
39 changes: 39 additions & 0 deletions packages/ember-glimmer/tests/integration/helpers/loc-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { RenderingTest, moduleFor } from '../../utils/test-case';
import Ember from 'ember-metal/core';

moduleFor('Helpers test: {{loc}}', class extends RenderingTest {

constructor() {
super();
this.oldString = Ember.STRINGS;
Ember.STRINGS = {
'_Howdy Friend': 'Hallo Freund'
};
}

teardown() {
Ember.STRINGS = this.oldString;
}

['@test it lets the original value through by default']() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests should go through the "The I-N-U-R cycle" mentioned in #13127.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops, right. Will fix that, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this only needs to check initial render and no-op rerender, not update and reset. Does that seem correct?

this.render(`{{loc "Hiya buddy!"}}`);
this.assertText('Hiya buddy!', 'the unlocalized string is correct');
this.runTask(() => this.rerender());
this.assertText('Hiya buddy!', 'the unlocalized string is correct after rerender');
}

['@test it localizes a simple string']() {
this.render(`{{loc "_Howdy Friend"}}`);
this.assertText('Hallo Freund', 'the localized string is correct');
this.runTask(() => this.rerender());
this.assertText('Hallo Freund', 'the localized string is correct after rerender');
}

['@test it takes passed formats into an account']() {
this.render(`{{loc "%@, %@" "Hello" "Mr. Pitkin"}}`);
this.assertText('Hello, Mr. Pitkin', 'the formatted string is correct');
this.runTask(() => this.rerender());
this.assertText('Hello, Mr. Pitkin', 'the formatted string is correct after rerender');
}

});
42 changes: 0 additions & 42 deletions packages/ember-htmlbars/lib/helpers/loc.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/ember-htmlbars/lib/helpers/loc.js
53 changes: 0 additions & 53 deletions packages/ember-htmlbars/tests/helpers/loc_test.js

This file was deleted.