-
Notifications
You must be signed in to change notification settings - Fork 432
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
feat: create with vue-i18n #548
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good start.
There should be at least one snapshot test to check that everything works.
Ideally, the should introduced a modified component template to use a translation that could be checked in a test.
.idea/vcs.xml
Outdated
<mapping directory="" vcs="Git" /> | ||
<mapping directory="$PROJECT_DIR$/playground" vcs="Git" /> | ||
</component> | ||
</project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you remove all the .idea
files that you added to this commit?
|
||
export default createI18n({ | ||
legacy: false, | ||
globalInjection: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thnink this is the default value, so the line can be removed
locale: 'en', | ||
fallbackLocale: 'en', | ||
messages | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, when used in TS, there are additional informations that should be added to have a proper typechecking:
https://vue-i18n.intlify.dev/guide/advanced/typescript.html
@cexbrayat
I've got it ! |
…5/create-vue into feat/create-with-i18n
@cexbrayat |
@Procrustes5 Sorry, I should have explained: to add a snapshot test, you don't have to open a PR on create-vue-templates, you have to update the |
@cexbrayat |
scripts/snapshot.mjs
Outdated
@@ -15,7 +15,8 @@ const featureFlags = [ | |||
'vitest', | |||
'cypress', | |||
'playwright', | |||
'nightwatch' | |||
'nightwatch', | |||
'vue-i18n' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be removed from here because it's going to generate too many snapshots
template/tsconfig/vue-i18n/i18n.d.ts
Outdated
export interface DefineLocaleMessage { | ||
hello: string | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this file should be necessary? With TypeScript, you need to do something like:
import { createI18n } from 'vue-i18n'
import enUS from './locales/en-US.json'
// Type-define 'en-US' as the master schema for the resource
type MessageSchema = typeof enUS
const i18n = createI18n<[MessageSchema], 'en-US'>({
locale: 'en-US',
messages: {
'en-US': enUS
}
})
"types": ["i18n"] | ||
}, | ||
"include": ["src/template/config/vue-i18n/**/*", "src/template/config/vue-i18n/**/*.json"] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And i think this file can be removed as well?
@cexbrayat |
@Procrustes5 import { createI18n } from 'vue-i18n'
import enUS from './locales/en-US.json'
type MessageSchema = typeof enUS
const i18n = createI18n<[MessageSchema], 'en-US'>({
locale: 'en-US',
messages: {
'en-US': enUS
}
}) Also, as a second step, the generated HelloWorld component could show the usage of |
Oh and I forgot something: the PR should also update |
…5/create-vue into feat/create-with-i18n
@cexbrayat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work. I'm just wondering if the components which are the same in the typescript-default
template could not be removed to avoid duplication. Other than that, looks good to me.
flex-wrap: wrap; | ||
} | ||
} | ||
</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file necessary? If it doesn't change from the typescript-default
versions, then I think it should not be duplicated if possible (same for the other components).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cexbrayat
Oh, I'd not understood this architecture yet. Thank you
modified now!
<div class="greetings"> | ||
<h1 class="green">{{ msg }}</h1> | ||
<h3> | ||
{{ t('greetings.message') }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@cexbrayat |
Description
issue : #545
Added vue-i18n to the option. I made it with the directory structure suggested in the above issue.