Skip to content
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

About __n & plural argument #86

Open
laendoor opened this issue Apr 13, 2020 · 2 comments
Open

About __n & plural argument #86

laendoor opened this issue Apr 13, 2020 · 2 comments
Labels

Comments

@laendoor
Copy link

Hi, first at all, this is a great & simpler package, it's very useful.

I'm thinking about the use of second/plural argument in __n function. Making some checks and viewing your tests and implementation, the second argument seems to be meaningless except for keeping it in a file if it doesn't exist. For example:

 it('allows an alternative locale to be set', function () {
  var __n = y18n({
    locale: 'pirate',
    directory: path.join(__dirname, 'locales')
  }).__n

  __n('%d cat', '%d cats', 1).should.equal('1 land catfish')
  __n('%d cat', '%d cats', 3).should.equal('3 land catfishes')
})

Here I can write __n('%d cat', 'foo bar', 3) and still get 3 land catfishes.
unknown
Perhaps it might be more useful (sometimes at least) to have another method y18n.__p(key, number, ...args) to use without worrying about updateFiles feature or maybe with a default "unknown" value.

I don't know... It's just a practical suggestion.

@laendoor laendoor changed the title About __n About __n & plural argument Apr 13, 2020
@QmarkC
Copy link
Contributor

QmarkC commented Aug 5, 2020

The current behavior only updates the cache and the language file if the singular is not found and updateFiles is true.
In your example __n('%d cat', 'foo bar', 3) only the plural was updated, which is why you still get 3 land catfishes.

So this might be a few different enhancements:

  • Update cache/language file if a new plural string is observed
  • Ability to update the cache w/o updating the language file, which would use the strings for the current instance of y18n.
  • A way to prefer the provided strings over the current cache such as new method or option to current method, which would use the provided strings for just that single call.
  • Set default of plural arg if there is a matching singular/quantity in the cache so that pluralString could be optional.

@leandrojdl did I interpret your suggestion correctly?

@bcoe bcoe added the bug label Sep 6, 2020
@bcoe
Copy link
Member

bcoe commented Sep 6, 2020

@leandrojdl thanks for the suggestion 👍

Would happily accept a patch to fix this, otherwise let's keep this open until someone can address.

@CarlosBellange
Copy link

Im sorry for the delay. It has happened a lot due the Covid and because of other organisations deprecating on purposes to delay my work and fooling around with the Atom program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants
@bcoe @laendoor @QmarkC @CarlosBellange and others