-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Glimmer2] Port {{loc}}
helper test to ember-glimmer
#13129
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?