Git Product home page Git Product logo

Comments (5)

caridy avatar caridy commented on May 11, 2024

@al3x-edge in the example, boundProperty should have the value of the message, which is:

boundProperty === `You have {numPhotos, plural,
    =0 {no photos.}
    =1 {one photo.}
    other {# photos.}}`

The other option is to use the lookup helper intl-get, which will simply try to find the message value by key, which is the recommended way.

from ember-intl.

lxcodes avatar lxcodes commented on May 11, 2024

@caridy Thanks for the answer -- Just as a follow up -- Is there a way to get the value of the message in a controller assuming it's injected?

from ember-intl.

jasonmit avatar jasonmit commented on May 11, 2024

Is there a way to get the value of the message in a controller assuming it's injected?

You want to resolve a translation key to a message from a computed property on your controller?

Based on your initial question, I'm unsure if you're dealing with a string literal or a translation key from your computed property, so I've included examples for both:

// index fontroller
export default Ember.Controller.extend({
    dependentKey: false,

    actions: {
        toggle: function () {
            this.toggleProperty('dependentKey');
        }
    },

    literalString: Ember.computed('dependentKey', function () {
        var dep = this.get('dependentKey');
        return dep ? 'yes' : 'no';
    }),

    lookupString: Ember.computed('dependentKey', function () {
        var dep = this.get('dependentKey');
        return dep ? 'messages.foo' : 'messages.bar';
    })
});
<button {{action 'toggle'}}>Toggle</button>

<div>
  Computed string literal:
  {{format-message literalString}}
</div>
<div>
  Computed translation key:
  {{format-message (intl-get lookupString)}}
</div>

from ember-intl.

jasonmit avatar jasonmit commented on May 11, 2024

@al3x-edge your last question might also be related to #89

Let me know

from ember-intl.

lxcodes avatar lxcodes commented on May 11, 2024

Thanks for the reference to #89 -- When asking the question, that is what I was looking for once the boundProperty didn't work. I'll keep this as reference.

Originally tried the second approach with setting a lookupString but was getting errors for some reason. Recently updated all dependencies though -- not sure if something took or I just did it right the second time around -- and everything is fine.

Thanks for the help (@jasonmit / @caridy ). Greatly appreciated.

from ember-intl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.