-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13129 from code0100fun/glimmer-loc-helper
[Glimmer2] Port `{{loc}}` helper test to `ember-glimmer`
- Loading branch information
Showing
5 changed files
with
88 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
packages/ember-glimmer/tests/integration/helpers/loc-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
|
||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../ember-glimmer/lib/helpers/loc.js |
This file was deleted.
Oops, something went wrong.