Giter VIP home page Giter VIP logo

Comments (9)

jamesarosen avatar jamesarosen commented on May 28, 2024

I have no problem breaking backwards compatibility in a major version release. That doesn't address the extra typing for the normal case (though I don't think that's a huge burden).

I don't like {{t order scope="buttons.order"}} because it's hard to tell that scope is special and not an interpolation for the translation.

I don't really like adding lots of really short helper methods (t might become i18n or translate in the future), so I don't love pt, but would be open to a second helper (like i18nProperty) method for the second case.

One tricky thing is that it might be very difficult to pass interpolations to the property case. It might be pretty easy. I'm just not sure.

from ember-i18n.

rlivsey avatar rlivsey commented on May 28, 2024

I'll have a think about how we could do this, I've currently got a pt helper in my app which works for what I need but doesn't do anything fancy like support options:

Ember.Handlebars.registerBoundHelper 'pt', (propName, options) ->
  key = if scope = options.hash.scope then "#{scope}.#{propName}" else propName
  Ember.I18n.t(key)

That handles the very basic case of the property name changing and a new translation appearing, but doesn't pass any options off.

Ember.I18n.t(key, options.hash) could do the trick and just delete the scope option before it gets passed in, but then there's no bindings on count or other options passed in etc...

As for scope I just used that as it's what Rails i18n calls it, maybe translationScope or keyRoot or something else?

If you're happy breaking backwards compatibility then I think it would be worth making the one helper support both strings and properties based on quoted/unquoted as that's a fairly common pattern with other Ember helpers.

from ember-i18n.

manoswerts avatar manoswerts commented on May 28, 2024

@rlivsey,

I just recently started working with Ember.js and Handlebars—so maybe I'm missing something—but shouldn't it be as simple as the following code snippet?

Ember.Handlebars.registerBoundHelper("pt", function(value) {
    return Ember.I18n.t(value);
});

I don't see why you need to resolve the key yourself. If you use a bound helper, the propName parameter should already be the resolved property value?

from ember-i18n.

rlivsey avatar rlivsey commented on May 28, 2024

@manoswerts that's so I can pass in a scope for the key.

Eg in my app I have an activity feed, the items in that feed have a type attribute.

My translations are structured something like:

Em.I18n.translations =
  'activity.title.action_created':      "created action"
  'activity.title.action_completed':    "completed"
  'activity.title.action_uncompleted':  "uncompleted"
  'activity.title.comment_posted':      "posted comment"

And then in my template I can do:

{{pt item.type scope="activity.title"}}

The alternative would be to have the object know about the full path, but then I have to litter my model with translation properties for each string:

App.FeedItem = Ember.Object.extend
  translatedTitleKey: (->
    "activity.title.#{@get("type")}"
  ).property("type")

At that point there's no real need for the helper because I could just as easily do the translations in the model:

App.FeedItem = Ember.Object.extend
  translatedTitle: (->
    Ember.I18n.t "activity.title.#{@get("type")}"
  ).property("type")

… but I don't think the model should know about its translations.

from ember-i18n.

jamesarosen avatar jamesarosen commented on May 28, 2024

I like the idea of a scope. Ruby's I18n has the same thing. If we implement this, we should pass the key and scope separately to findTemplate so that different backends can treat scope differently. (As opposed to passing "{{scope}}.{{key}}" to findTemplate.)

from ember-i18n.

garjust avatar garjust commented on May 28, 2024

My team recently implemented a little helper to do this

{{dt "roles" name}} -> "roles.#{name}"
{{dt "hip" "hop" "hurray"}} -> "hip.hop.hurray"
{{dt "roles" name "title"}} -> "roles.#{name}.title"

What do you think about this interface? It makes it easy to chain multiple dynamic parts.

from ember-i18n.

jamesarosen avatar jamesarosen commented on May 28, 2024

The last example -- {{dt "roles" name "title"}} won't work on Ember 0.9, but does on 1.0. Thus, if we support it (which I'm fine with), it would have to be on the v2.0 branch, which only supports Ember 1.0.

from ember-i18n.

jamesarosen avatar jamesarosen commented on May 28, 2024

See also #113, which doesn't do exactly that, but is similar.

from ember-i18n.

jamesarosen avatar jamesarosen commented on May 28, 2024

I'm going to close this in favor of #131. If that ends up not working for this use-case, we can always reopen this.

from ember-i18n.

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.