Skip to content

Commit

Permalink
Merge pull request #13129 from code0100fun/glimmer-loc-helper
Browse files Browse the repository at this point in the history
[Glimmer2] Port `{{loc}}` helper test to `ember-glimmer`
  • Loading branch information
chancancode committed Mar 19, 2016
2 parents 94964e1 + 91086b7 commit a358c59
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 96 deletions.
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']() {
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.

0 comments on commit a358c59

Please sign in to comment.