Comments (7)
I get a Promise Object but I need the result as a String in a for-loop
Can you explain what you're doing? Maybe I can offer up a solution but here is what I have that should work. There may be a real use case here that I can build support around.
Here is how you might achieve this (untested, should work):
export default Ember.Controller.extend({
intl: Ember.inject.service(),
actions: {
thingy: function () {
var intl = this.get('intl');
intl.getTranslation('messages.photos').then(function (result) {
// not sure what version of ember-intl you are using
// so it's either `content` or `translation`
var output = intl.formatMessage(result.translation || result.content, {
name: 'Name'
numPhotos: 1000
takenDate: new Date()
}, {
locales: result.locale
});
console.log(output);
}.bind(this));
}
}
});
Edit: fixed a bunch of typos
from ember-intl.
Thanks for the quick response.
Currently I have a loop like:
myList: function() {
return this.get('model').map(function(itemData) {
var message = '';
switch(itemData.get('type')) {
case 'point':
message = '+' + itemData.get('value') + ' ' + itemData.get('message');
break;
case 'playerJoined':
message = 'Joined the game';
break;
case 'playerLeft':
message = '"' + itemData.get('message') + '" has left the game';
break;
case 'settingPointChanged':
message = 'Edit Settingpoint: ' + itemData.get('message') + '<br/>New Point: +' + itemData.get('value');
break;
//......
}
}
}
And many more messages with different types and messages. This message I want to localized. And this is where Iam need a method that is returning a simple Object or String with paramters.
from ember-intl.
This branch supports your use-case of findTranslation
returning a simple object: https://github.com/yahoo/ember-intl/tree/2.0
The returned object contains two properties: content
(your translation string) and locale
where the translation came from.
Notable changes needed in order to port your app to use this branch:
- Move your translations from
/app/locales
to/translations
(outside of app folder) - Your translation files should now be json files, instead of es6 modules. if you need an example just look at the dummy app:
https://github.com/yahoo/ember-intl/tree/2.0/tests/dummy - Your
config/environment
should look something similar to:
module.exports = function(environment) {
var ENV = {
intl: {
defaultTranslation: 'en' // your default locale
}
// ..
}
return ENV;
}
The default translation right now is required, and it's the locale in which you want your application to fallback to when a translation key is omitted from any of the other locales your app supports. At build time, you'll see warnings when a translation does not contain a key that your default locale's translation file contains. This makes the default really the source of truth for all other locale translations.
This will hopefully be released in a few weeks, but it's very alpha right now. I'd recommend just sitting tight and continue to use your working solution and I'll close this issue once 2.0 is on master and stable.
from ember-intl.
Thanks again!
Thanks for the informations. Currently Iam in production mode. So its better to wait for the stable release as you say.
Just a note, I have integrate format.js 1.2.1 in my ember-cli 0.2.1 and ember 1.13-canary project and after that, all works fine in my browser (Chrome) but on my phone (iPhone) or with iOS - Emulator with cordova, I see the splashscreen and after that only a blank page. Nothing else with no error message.
But these only as a note because I didnt debug it and just removed the ember-intl.
Thanks for your work and sharing this project!
from ember-intl.
thanks for the question, turned out useful for me also, another question is would this be safe or is there a formatHtmlMessage function that I should make instead?
var intl = this.get('intl');
return intl.getTranslation('messages.product.html.info').then(function (result) {
var messageHtml = intl.formatMessage(result.translation || result.content, {
product: 'Apple watch',
price: 200
}, {
locales: result.locale
});
});
from ember-intl.
Thanks for the question, turned out useful for me also, another question is would this be safe or is there a formatHtmlMessage function that I should make instead?
That's not safe, and I don't expose that as a method from the service to do it. What you'll want to do is wrap that messageHtml
in Ember.String.htmlSafe
@jcope2013
from ember-intl.
I see the splashscreen and after that only a blank page. Nothing else with no error message.
@svox1 You'll likely need to load the Intl polyfill, the README at the top covers instructions on how to do that.
from ember-intl.
Related Issues (20)
- Missing fast-memoize module when updating ember-auto-import HOT 1
- Problems with adding Somali language - intl-numberformat error HOT 7
- When will there be another release? HOT 1
- Type issues from Registry HOT 6
- Type issues from -format-base.d.ts HOT 1
- bump typescript peer dependency to 5 HOT 3
- trailingZeroDisplay not working HOT 2
- FORMAT_ERROR when using the `Intl.RelativeTimeFormat` polyfill with `v6.0.0` of ember-intl HOT 3
- Double `intl.d.ts` cause type errors HOT 8
- Unexpected locale `en-us` after upgrade to ember-intl v6 HOT 6
- A simple, autogenerated integration test fails for a component using a translation in ember-intl 6.1.2 HOT 6
- Bundle size regression in v6.2.0 HOT 3
- Merge this into formatjs HOT 3
- Incompatible with native `ember-source` types HOT 5
- `allowEmpty` class property not respected in v6.3.1 HOT 1
- Extending helpers like FormatDate has braking changes between v6.2.2 and v6.3.0+ HOT 5
- Basic usage results in: You attempted to update `_locale` [...] infinite revalidation bugs, and performance issues, and is not supported. HOT 4
- How to use `publicOnly: true` in Embroider apps HOT 10
- v6 - Error on valid use of `many`: message cannot be parsed: Unknown plural category: many HOT 1
- Deleted
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ember-intl.