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

Add links to alternative languages, meta locale, OpenGraph locale #26

Open
fabianmichael opened this issue Jan 10, 2023 · 7 comments
Open
Labels
enhancement New feature or request

Comments

@fabianmichael
Copy link
Owner

fabianmichael commented Jan 10, 2023

E.g.

See

There needs to be an API/hook to filter out incomplete versions of secondary languages, so they can also be removed from the XML sitemap.

@fabianmichael fabianmichael added the enhancement New feature or request label Jan 10, 2023
@Daandelange
Copy link
Contributor

After reading some more docs, regarding the og:locale:alternate, I doubt its usefulness. Some people are wondering if Facebook still uses them, and if still used, you're supposed to listen for ?fb_locale=fr_FR when the server pings back (requires adding a kirby route-->url-rewrite?), and you need to serve the corresponding translation. Otherwise this tag doesn't seem to do anything, plus it feels weird to indicate that a content translation is available without serving its URL.

og:locale still seems useful to indicate the content language and it's already present.
Note that it currently serves a language code, not a locale. (fr instead of fr_FR).

@fabianmichael
Copy link
Owner Author

fabianmichael commented Jan 24, 2023

@Daandelange Let’s omit the OpenGraph stuff then and just add the alternate meta tags.

Daandelange added a commit to Daandelange/kirby-meta that referenced this issue Jan 24, 2023
@Daandelange
Copy link
Contributor

Daandelange commented Jan 24, 2023

Tree commits :

  1. The base functionality (tested in multilang with-and-without languages.detect).
    Untranslated content is not served as "alternate".
    x-default is set according to languages.detect or to english with a fallback to the default language.
    image

  2. Custom lang switcher url setting.

  3. Send content-language in HTTP-Headers too.
    image

I'm not sure you'd want them all, haha. (you can pick just one)

@fabianmichael
Copy link
Owner Author

@Daandelange Thas already looks like a great start, thank you! :-) My only concern is, that most of the logic is contained within the snippet. I’d prefer to have all of that within the PageMeta class and just handle the HTML-generating part within the snippet. That said, using <link>s is probably the most transparent way of serving this to the client and will also work better with https://github.com/getkirby/staticache on cheap hosting.

We also need to ensure, that we got the same implementation for generating the links in the Sitemap (see https://github.com/fabianmichael/kirby-meta/blob/main/src/Sitemap.php#L87-L97). Like I mentioned earlier, in some of my project I got additional options for disabling languages or translations of single pages in the panel. I also got a project, where translations of news articles are generated automatically by DeepL and just stored in the cache. On that project, the translated content does never exist, even if a translation of a page exists. Another example: Let’s say I got a page called "Blog", that does not have any content on it’s own. The title "Blog" works for many languages, so most translations of that page might never be created. TL;DR: Using $page->translation($lang->code())->exists() is quite smart, but I see many pitfalls/edge cases where it would fail.

I think having something like a $pageMeta->translations() method that fires a hook, e.g. meta.translations:after would be the best way for supporting all possible scenarios. What do you think?

@Daandelange
Copy link
Contributor

Thanks for these explanations, didn't think about such scenarios. (in scenario 1 $virtualPage->translation() could/should be implemented in such scenarios, no ?)
Anyways, that makes perfectly sense to me, let's go for it.

Daandelange added a commit to Daandelange/kirby-meta that referenced this issue Feb 5, 2023
Daandelange added a commit to Daandelange/kirby-meta that referenced this issue Feb 5, 2023
@Daandelange
Copy link
Contributor

Hey, I'm almost there but there's a choice to make first.

How to access/share $pageMeta->alternateLanguages() for usage within Sitemap->urlsForPage() ? Maybe alternateLanguages() shouldn't be in PageMeta and not be <link rel...> oriented ?

Also, I've rather opted for meta.alternateLanguages:after & $pageMeta->alternateLanguages() to avoid confusion with content translations and be more explicit.

@fabianmichael
Copy link
Owner Author

How to access/share $pageMeta->alternateLanguages() for usage within Sitemap->urlsForPage() ? Maybe alternateLanguages() shouldn't be in PageMeta and not be oriented ?

Does anything speak against accessing PageMeta->alternateLanguages()from a Sitemap-method?

I like the idea of defining the method in more abstract form, so it could easily be used in different scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants