Giter VIP home page Giter VIP logo

Comments (7)

jamesarosen avatar jamesarosen commented on June 20, 2024

Can you show the relevant translations? Do you have multiple locales? What version are you using?

Given 'prototypes.defaultNewPrototypeName', {count: 3}, ember-i18n doesn't know whether you have translations like

prototypes:
  defaultNewPrototypeName: 'something with {{count}}'

or like

prototypes:
  defaultNewPrototypeName:
    one: 'one new default property name'
    other: '{{count}} new default property names'

So it first looks for prototypes.defaultNewPropertyName.other, then falls back to prototypes.defaultNewPropertyName.

We'll need more of your setup to be able to replicate the failure.

from ember-i18n.

cbou avatar cbou commented on June 20, 2024

As you said, I think it's related to my setup.

I play a bit with a twiddle and it seems to be ok: https://ember-twiddle.com/#/910eefc652a09838b15674ffe8e39cd3

I will reopen the issue if I find an error I can't explain.

from ember-i18n.

cbou avatar cbou commented on June 20, 2024

Thanks!

from ember-i18n.

cbou avatar cbou commented on June 20, 2024

Sorry, now I was able to reproduce the issue.

https://ember-twiddle.com/910eefc652a09838b15674ffe8e39cd3

console.log(this.get('i18n').t('plural', {count: 1}).toString()); // Missing translation: plural
console.log(this.get('i18n').t('plural', {count: 0}).toString()); // Zero plural
console.log(this.get('i18n').t('plural', {count: 1}).toString()); // Zero plural

This is strange to me, I would expect that t('plural', {count: 1}) always returns the same string.

from ember-i18n.

jamesarosen avatar jamesarosen commented on June 20, 2024

I won't be able to look into this in the near future, but I hope that this excellent reproduction will make it easy for the community to solve :)

from ember-i18n.

tehmaestro avatar tehmaestro commented on June 20, 2024

The problem is that both _defineMissingTranslationTemplate and _compileTemplate set this.translations[key] = something; and they do not take into account inflection generated by pluralForm , I think :)

I believe the two functions should receive the full key path, including the inflection, if count was set.
I am doing something like this:
Edit: I updated the code

  findTranslation(fallbackChain, count) {
    if (this.translations === undefined) { this._init(); }

    let inflection;
    if (count != null) {
        inflection = this.pluralForm(+count);
    }
    let result;
    let i;
    for (i = 0; i < fallbackChain.length; i++) {
      let key = fallbackChain[i];
      if (count != null) {
        result = this.translations[`${key}.${inflection}`];

        // If result is null, fallback
        if(result == null) {
            result = this.translations[key]
        }
        // Always use key with inflection
        key = `${key}.${inflection}`;
      } else {
          result = this.translations[key]
      }

      if (result) {
        return {
          key: key,
          result: result
        };
      }
    }

    return {
      key: count == null ? fallbackChain[0] : `${fallbackChain[0]}.${inflection}`,
      result: result
    };
  },

from ember-i18n.

jamesarosen avatar jamesarosen commented on June 20, 2024

jamesarosen/ember-i18n has been deprecated in favor of ember-intl.

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.