cyon / vue-translation-manager

Interactively translate strings in Vue single file components
26 stars 12 forks source link

Add support for message parameters #4

Closed MaxGfeller closed 5 years ago

MaxGfeller commented 6 years ago

Both vue-i18n and vuex-i18n support passing dynamic parameters to messages. Example:

<h1>{{ $t('hello.title', { name: 'Max' }) }}</h1>
{
  "hello": {
    "title": "Hallo, {name}"
  }
}

The vue-translation-manager should also be able to support those kinds of messages. The following should be detected and in the interactive prompt, the user should be instructed to insert those parameters.

<span>Hallo {{ name }}</span>
marlass commented 6 years ago

I would like to help you with that. Do you have some requirements about how it should be done or do I have freedom with the implementation?

marlass commented 6 years ago

Just to be sure. In the example you provided the final name won't be provided by user, but it will point to the same variable that was used before transformation.

Should that be result of the code?

<h1>{{ $t('hello.title', { name }) }}</h1>

For even more tricky example that would work I imagine it would work as below.

<p>Hello {{ male ? 'Mr' : 'Ms' }} {{ firstname }} {{ lastname }}</p>

That would require user to provide inside translation 3 placeholders with unique names. Example: "Hello {gender} {firstname} {lastname}". Not providing 3 placeholders should result in error?

Output would be:

<p>{{ $t('hello.title', { gender: male ? 'Mr' : 'Ms', firstname, lastname }) }}</p>
MaxGfeller commented 6 years ago

That sounds great @marlass! This is exactly right, that's how it should be transformed.

I don't have any requirements but please make sure there is a test case for it and that your code follows the Standard coding style.

marlass commented 6 years ago

I edited a comment above. Added some more advanced example. Could you take a look one more time?

MaxGfeller commented 6 years ago

Aight, that sounds very reasonable. Although i wouldn't make it result in an error if not all the parameters are specified. Theoretically those could be added only later too.