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

Combining Single File Component syntax with root messages #172

Closed
ccamarat opened this issue Jun 9, 2017 · 4 comments
Closed

Combining Single File Component syntax with root messages #172

ccamarat opened this issue Jun 9, 2017 · 4 comments
Labels
Type: Bug Bug or Bug fixes

Comments

@ccamarat
Copy link

ccamarat commented Jun 9, 2017

I was kicking the tires a bit and ran into an unexpected problem. It appears one cannot reference the root translation node from within an <i18n> block inside an SFC.

main.js

import VueI18n from 'vue-i18n';
Vue.use(VueI18n);
const i18n = new VueI18n({
  locale: 'en',
  messages: {
    'company-name': 'billy-bob\'s fine steaks.'
  }
});

Sample.vue

<i18n>
  {
    "en": {
      "title": "@:company-name - yeee hawwww!!!"
    }
  }
</i18n>

<template>
  <div id="app" class="container">
    <site-header :title="$t('title')"></site-header>
  </div>
</template>

Without the <i18n> block, company-name can be bound to :title. Interestingly, both properties can be accessed from within a computed property as suggested in this helpful SO answer.

@kazupon
Copy link
Owner

kazupon commented Jun 10, 2017

You need to define the locale (e.g. en).
Please see the Locale messages syntax section.
https://kazupon.github.io/vue-i18n/en/messages.html

@kazupon kazupon closed this as completed Jun 10, 2017
@ccamarat
Copy link
Author

The sample code above was pasted incorrectly; it should have been:

/static/i18n/en.json

{
    "company-name": "billy-bob\'s fine steaks."
}

main.js

import VueI18n from 'vue-i18n';
import langEn from '/static/i18n/en.json';
Vue.use(VueI18n);
const i18n = new VueI18n({
  locale: 'en',
  messages: {
    en: langEn
  }
});

As mentioned in the original, without the <i18n> block, company-name can be bound to :title and work properly. The problem only occurs if the root node is referenced from within the <i18n> block.

I apologize for the red herring in the original post; I'd thought I double-checked it.

@kazupon
Copy link
Owner

kazupon commented Jun 11, 2017

Could you provide the minimum reproduction repo please?

@ccamarat
Copy link
Author

Should just be this:

/static/i18n/en.json

{
    "company-name": "billy-bob's fine steaks."
}

main.js

import VueI18n from 'vue-i18n';
import langEn from '../static/i18n/en.json';
Vue.use(VueI18n);
const i18n = new VueI18n({
  locale: 'en',
  messages: {
    en: langEn
  }
});

Sample.vue

<i18n>
  {
    "en": {
      "title": "@:company-name - yeee hawwww!!!"
    }
  }
</i18n>

<template>
  <div id="app" class="container">
    <site-header :title="$t('title')"></site-header>
  </div>
</template>

In case there's something I missed I created a demo project using the Vue CLI, which you can see running here.

@kazupon kazupon reopened this Jun 12, 2017
@kazupon kazupon added the Type: Bug Bug or Bug fixes label Jun 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug or Bug fixes
Projects
None yet
Development

No branches or pull requests

2 participants