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

Linked Pluralization #195

Closed
zecar opened this issue Jul 12, 2017 · 21 comments
Closed

Linked Pluralization #195

zecar opened this issue Jul 12, 2017 · 21 comments
Labels
Priority: High Type: Feature Includes new features

Comments

@zecar
Copy link

zecar commented Jul 12, 2017

using vue 2.2.6 and vue-i18n 6.1.1

Can this be done?
I'm trying to do a "action string"
ex: User added 1 photo - if there are more photos i want to show "photos"

i have this

export default {
	en: {
		actions: {
			photo: 'added {count} @:photo'
		},
		photo: 'photo | photos'
	}
}

How do I pass the count parameter in a pluralized linked locale message ?

@zecar
Copy link
Author

zecar commented Jul 27, 2017

up ?

@amertum
Copy link

amertum commented Jul 27, 2017

IMHO, you should not use "Linked message" (using @:) as it provides more complexity over usefulness. Having duplicated string in i18n messages is normal and provide flexibility and room for change.

@zecar
Copy link
Author

zecar commented Jul 28, 2017

@amertum just to be sure i understand what you are saying

I should have two strings in my locales file, one for singular and one for plural and to have something like {{ data.length > 0 ? $t('singular') : $t('plural') }} ?

@amertum
Copy link

amertum commented Jul 28, 2017

What I meant was :

export default {
  en: {
    actions: {
      photo: 'added 0 photo | added 1 photo | added {0} photos'
    }
  }
}
{{ $tc('actions.photo', count, [count]) }}

I agree that the documentation should be more prolixe about this. But it is clear in the source code ^^.

@smares
Copy link

smares commented Aug 28, 2017

I have a slightly different, but related problem. I have a set of common words together with their plural form in a common.json file. Then I have components that come with their own loca file. What I would like to do is have the component loca link to a common word in its singular form. Can this be done? Currently, if my common file has something like "common": { "artist": "Artist | Artists" } and the component loca "artist": "@:common.artist" and I use $t("artist"), I get Artist | Artists.

@amertum
Copy link

amertum commented Aug 28, 2017

@smares Duplicate strings is not a bad thing in messages. You should not seek for hard normalization. It will be difficult to maintain and it does not handle well with other languages pluralizations.

@rijkvanzanten
Copy link

While I agree with @amertum's point on duplicates not being a bad thing ,I don't fully agree with the points on maintenance and other languages causing problems

In my particular use case:

// en.js
export default {
  name:            'Name',
  collection:      'Collection | Collections',
  file:            'File | Files',

  collection_name: '@:collection @:name',
  file_name:       '@:file @:name'
};

the names collection and file are used in a lot of different instances (this is only a subset) and don't change between instances. By using the linked locale messages feature, we can prevent spelling errors by only having to enter the "general" terms once.

Next to this, additional translations can be a lot smaller by using the fallback language for the combined messages like follows:

// nl.js
export default {
  name:            'Naam',
  collection:      'Collectie | Collecties',
  file:            'Bestand | Bestanden',

  // use English fallback for collection_name & file_name
};

If the combined message doesn't fit well in the other language, the linked locale message can be updated on a per-instance basis:

// nl.js
export default {
  name:            'Naam',
  collection:      'Collectie | Collecties',
  file:            'Bestand | Bestanden',
  
  // use English fallback for collection_name

  // Override file_name for Dutch
  file_name: '@:name van het @:file'
};

First syntax ideas:

@:apple
@:apple(1)
@:apple(10, { count: 10 })

OR:

@:apple
@:apple:1
@:apple:10:{"count": 10}

@kazupon What are your thoughts on the matter? Would you be interested in figuring out an addition to the linked locale message syntax in order to support pluralization?

@razvanioan
Copy link

if I'm reading this, I guess I'm needing this 👍

@SuperDJ
Copy link

SuperDJ commented Apr 7, 2018

If this isn't possible I think linking and plural is kind of redundant as you still need to type the full sentence where you would otherwise just use a mix of plural and linked. Yes the functionals are usefull on their own but if you could mix them it would be event better.

@brunosmm
Copy link

Hello all,

Is there any update on this issue?

@SDenman
Copy link

SDenman commented Jan 11, 2021

This would be useful. The case that brought me here was to create translation files for time-stamping items such as messages. i.e. received {count} minutes ago
where minutes could be replaced with hours or days for example.
Unless someone has a better solution for this :)

@fabiante
Copy link

Hi there. I am not familiar with this projects label structure, what does the Status: Ready label indicate?

@kazupon
Copy link
Owner

kazupon commented Mar 5, 2021

we supported in Vue I18n v9.
please try it!

@zecar
Copy link
Author

zecar commented Mar 5, 2021

we supported in Vue I18n v9.
please try it!

How do I exactly try v9? I only see v8 on github

@exoego
Copy link
Collaborator

exoego commented Mar 5, 2021

v9 can be found on https://github.com/intlify/vue-i18n-next

@dani-fmena
Copy link

dani-fmena commented Dec 16, 2021

Can anyone tell me which was the syntax chosen for this in v9 version? Thanks in advance.

@cuongvuong-phoenix
Copy link

cuongvuong-phoenix commented Feb 17, 2022

Can anyone tell me which was the syntax chosen for this in v9 version? Thanks in advance.

Hi, I've found out the way to use it. You need to provide the plural number like the way we use pluralization in general:

  • Message (YAML):
    note: Note | Notes
    foo-note: Foo @:note
  • Template:
    <p>{{ t('foo-note', 1) }}</p>
    <p>{{ t('foo-note', 2) }}</p>
  • Rendered HTML:
    <p>Foo note</p>
    <p>Foo notes</p>

⚠️ By using this way, every linked message that has a pluralization definition will be rendered in the plural form. For example:

  • Message (YAML):
    note: Note | Notes
    todo: Todo | Todos
    foo-note-todo: Foo @:note @:todo
  • Template:
    <p>{{ t('foo-note-todo', 1) }}</p>
    <p>{{ t('foo-note-todo', 2) }}</p>
  • Rendered HTML:
    <p>Foo note todo</p>
    <p>Foo notes todos</p>

I hope Vue I18n will support providing plural numbers directly in linked messages like what @rijkvanzanten suggested.

@dani-fmena
Copy link

dani-fmena commented Feb 19, 2022

@vuong-cuong-phoenix thanks for the tip, that helps.

@zhouxianjun
Copy link

but v9 don't supports vue2 so sad

@botmaster
Copy link

Can anyone tell me which was the syntax chosen for this in v9 version? Thanks in advance.

Hi, I've found out the way to use it. You need to provide the plural number like the way we use pluralization in general:

  • Message (YAML):
    note: Note | Notes
    foo-note: Foo @:note
  • Template:
    <p>{{ t('foo-note', 1) }}</p>
    <p>{{ t('foo-note', 2) }}</p>
    
  • Rendered HTML:
    <p>Foo note</p>
    <p>Foo notes</p>
    

⚠️ By using this way, every linked message that has a pluralization definition will be rendered in the plural form. For example:

  • Message (YAML):
    note: Note | Notes
    todo: Todo | Todos
    foo-note-todo: Foo @:note @:todo
  • Template:
    <p>{{ t('foo-note-todo', 1) }}</p>
    <p>{{ t('foo-note-todo', 2) }}</p>
    
  • Rendered HTML:
    <p>Foo note todo</p>
    <p>Foo notes todos</p>
    

I hope Vue I18n will support providing plural numbers directly in linked messages like what @rijkvanzanten suggested.

Hello,

Is there a workaround to this issue?

@russo97
Copy link

russo97 commented Sep 17, 2024

Can anyone tell me which was the syntax chosen for this in v9 version? Thanks in advance.

Hi, I've found out the way to use it. You need to provide the plural number like the way we use pluralization in general:

  • Message (YAML):
    note: Note | Notes
    foo-note: Foo @:note
  • Template:
    <p>{{ t('foo-note', 1) }}</p>
    <p>{{ t('foo-note', 2) }}</p>
    
  • Rendered HTML:
    <p>Foo note</p>
    <p>Foo notes</p>
    

⚠️ By using this way, every linked message that has a pluralization definition will be rendered in the plural form. For example:

  • Message (YAML):
    note: Note | Notes
    todo: Todo | Todos
    foo-note-todo: Foo @:note @:todo
  • Template:
    <p>{{ t('foo-note-todo', 1) }}</p>
    <p>{{ t('foo-note-todo', 2) }}</p>
    
  • Rendered HTML:
    <p>Foo note todo</p>
    <p>Foo notes todos</p>
    

I hope Vue I18n will support providing plural numbers directly in linked messages like what @rijkvanzanten suggested.

Hello,

Is there a workaround to this issue?

Hello, everyone

Any news about this issue? I need to pluralize two differents terms in the same message, each of them should get its own counter

result: "{n} resultado | {n} resultados"
founded: "{count} encontrado | {count} encontrados"
count: "Mostrando @:page.result de @:page.founded"

I did try to pass n and count in explicity way but not get it to work

t('count', {
  n: 1,
  count: 7
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: High Type: Feature Includes new features
Projects
None yet
Development

No branches or pull requests