-
-
Notifications
You must be signed in to change notification settings - Fork 483
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: add dir property and defaultDirection option #1023
Conversation
Hey @rchl, can you review this if you got a time? |
Yes, sorry for the delay. Will do ASAP. |
What I really don't like about this is that it uses a global mixin. It causes unnecessary work for both Vue and Vue-meta and is the reason why I would ask you to investigate https://vue-meta.nuxtjs.org/api/#meta-addapp instead. I was meaning to look into it for the SEO functionality but it would be nice to try it first on a smaller feature like this one. Judging from the documentation it should be pretty easy to register an app with it and then update it whenever the locale changes. |
make sense. i just implemented it this way to follow the convention used with SEO functionality. I will take a look on the vue-meta later today. |
as per docs, if we used |
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.
as per docs, if we used
vue-meta
we will have to inject a function as same as the recommended solution for SEO, since$meta()
can only be accessed through a component. is it the intended approach?
In theory it can be accessed from the plugin's code also with something like:
const metaApp = Vue.prototype.$meta().addApp('i18n')
but I'm not sure if this is OK conceptually or more like a hack.
@pimlie maybe you could chime in here? Is that an OK way to add a VueMeta App? If not, maybe there should be some official way to access meta $meta
from a Nuxt plugin?
it will work, but we will not be able to re-set the meta when locale changes (from client side), or this at least what i noticed. import Vue from 'vue'
export const setHeadMeta = function (context) {
const {app} = context;
const metaApp = Vue.prototype.$meta().addApp("i18n");
const currentDir = app.i18n.localeProperties.dir || undefined;
metaApp.set({
htmlAttrs: {
dir: currentDir,
}
})
} and get called when locale changes: app.i18n.locale = newLocale
app.i18n.localeProperties = klona(locales.find(l => l[LOCALE_CODE_KEY] === newLocale) || { code: newLocale })
setHeadMeta(context) it will work only in the initial render, after locale changes it won't, i read a bit in |
It seemed to work for me when I've tested before (in a slightly different way). Did you see where it goes wrong exactly? Does it seem like a bug in vue-meta? |
i haven't really reached any conclusions, but it seems like |
@rchl $meta should also be available from the Nuxt Context which you have access to in Nuxt modules and plugins |
Tried different variations including:
and it doesn't seem to be available. It's also not visible in |
Hmm, yeah. So if you want to use addApp your best solution would probably be to get the component instance from the current page through vue-router matched components. You might have to wait for that instance to become available. But addApp is centered around Vue instances indeed and just doesnt work statically. Alternatively you could try to overwrite |
That one appears to be just adding a global mixin rather than working on |
so, what's your decision for this @rchl? |
I'm still against a global mixin so the only idea I have left is exposing a function like In the future, in a breaking version, I would probably remove the global SEO mixin completely and require the user to use |
this would be much better, i will commit the required changes tomorrow morning. also, i'm thinking about adding a |
Simple destructuring like:
should work since there are no overlapping properties in those two.
Sure |
Since we're adding the |
Why do you think there would be an overlap? The SEO functionality doesn't set anything in EDIT: No sorry, it does. Was searching for |
New plan:
EDIT: To be fair, it probably would make no difference if the SEO attributes would be added both through the |
This's the best plan. I was thinking about all possible edge cases, it seems like with this approach we will ONLY not be able then to disable/enable SEO on specific pages, i checked and it's also the current behavior when using |
Yes, disabling SEO per-page is broken already - #932 |
8fa5b86
to
0ed635f
Compare
955a605
to
8a2a5af
Compare
Thank you too, couldn't be done without your guidance. I committed the changes, and here's some points might need to be discussed:
export const nuxtI18nHead = function (addDirAttribute = true) {
if (addDirAttribute) {
// add dir attribute
} if this needs to be changed to a different approach, we might allow the
|
I've refactored a bit so that we could remove the |
Way much better, i've only fixed the links to |
Added something to that effect but wouldn't be surprised if I've overlooked something. |
Awesome, looks good. |
Thanks for your great work. |
Guys, thanks for everything you're doing. It's really a great tool. By the way, you have already updated docs, and people like me are looking for |
Released in https://github.com/nuxt-community/i18n-module/releases/tag/v6.19.0 (Also added version annotations in documentation to indicate from which version the new properties/options were added - 90a1959) |
i've made some changes to manage the case when the seo is enabled, which required changing the name of
plugin.seo.js
for clarity. Current scenario is: if the dir property is defined it will be used in the html's dir attribute, if not, or the locales form is an array of codes, the dir property will be set to undefined and the attribute will not be added.discussion: #762