jekyll-language-plugin icon indicating copy to clipboard operation
jekyll-language-plugin copied to clipboard

Default locale

Open calmyournerves opened this issue 9 years ago • 11 comments

Hi there, thanks for this plugin! I was wondering if it's possible to define a default locale or if you have plans to implement something like that. Or are there other ways to manage that?

Cheers!

calmyournerves avatar Nov 20 '15 08:11 calmyournerves

Well what do you imagine under a 'default locale'? Do you want one 'default' language that does not render inside a /:language subdirectory but rather directly inside the destination directory? That's currently not possible and I do not plan on implementing that since that is breaking the directory structure and you can easily fix that with a page redirect.

Is a page redirect to a 'default locale' what you want? You'd have to implement that by yourself. Therefore, check out root-index.html. This page has a / permalink which instructs Jekyll to omit the :language URL placeholder. Thus, although the page is in English as per front-matter, it is placed directly inside the destination directory.

Also, look into the YAML front-matter wiki page.

As an idea, you could write a JavaScript that figures out the browsers language and automatically redirects the user to the optimal language for him or herself.

vwochnik avatar Nov 20 '15 09:11 vwochnik

I have implemented automatic language redirect for the example page. Check out the commit 27e6c422c7b7a68f86874c83ffabd8e1c65f7b82.

vwochnik avatar Nov 20 '15 11:11 vwochnik

A default that does not render inside a subdirectory is what I thought about. I know there are other ways to do, but I wanted to know what your thoughts are about it. Thanks for the example and the explanation!

calmyournerves avatar Nov 20 '15 15:11 calmyournerves

Hello! Sorry to resurrect a closed issue but I think this issue could use some further thought. This plugin does a very good job of implementing localization. I'm glad I found it.

Unfortunately a javascript redirect to a default language is considered sub-optimal in my case. For an opensource project our default language is English and we are attempting to support multiple languages going forward. Not having a default language pollutes my default URI scheme a bit and doesn't give the best user experience. There are other javascript location redirects that happen in my default page that will conflict with the localization redirect. Additionally, some care is going into the URI scheme to enhance SEO optimization and I don't think a default redirect is optimal for indexing. Even with the root-index.html solution, any clicks off the main page will cause links to happen to /en instead of the default lang.

My hope for using this plugin is that the project will always use english as it's default documentation source and we can slowly recruit volunteers to provide further translations.

I've attempted to duplicate page content without language settings in hopes that it would create a 'default' view in the destination directory, but I receive build errors

  Liquid Exception: No language specified for current page or post. in _layouts/skeleton.html

Is there any other work around for this?

lordnynex avatar Dec 26 '15 21:12 lordnynex

The exception is being triggered because you probably removed the language YAML front-matter from one of the pages of the example site. That is of course not working since the skeleton layout requires a page or post to have a language.

What you want is a language_default setting which directs the plugin to omit the /:language URL template prefix so you can have a nicer URI scheme.

vwochnik avatar Dec 27 '15 08:12 vwochnik

:+1: for this.. any suggestion? There is no sense adding a language slug on each default language url.

equinusocio avatar Apr 12 '16 14:04 equinusocio

@calmyournerves Well, if you are looking for a fallback language you can achieve this with markdown standard. I did this, I have on lang.yml with multiple translations but not every language has a translation (just to reduce redundant data) and still Jekyll works. The trick is to use links. Here is a snippet of my lang.yml file:

# English (default)
# -----------------
en: &DEFAULT_EN
  site: 
    title: Jekyll
    description: Welcome

# German
# -----------------
de: &DEFAULT_DE
  <<: *DEFAULT_EN
  site:
    description: Willkommen
at:
  <<: *DEFAULT_DE
chde:
  <<: *DEFAULT_DE
    description: Grüezi

Result: the Swiss site (chde) inherits the translation from German site (de), the German site (de) inherits from English site (en), for all keys not included in the specific language. In the example the key site is the same in all languages, key description is different in en, de and chde but not in at. This reduces the amount of redundant translation data and the time to maintain translations. Hope this is the answer you are looking for, maybe it helps you.

Viele Grüße nach Zürich aus Luzern.

git-no avatar Jul 30 '16 06:07 git-no

Hi @vwochnik , I have checked your plugin. Looks better than others and also easy to understand. I have to ask one thing - Is there any update in setting a default language for a site? What I need is exactly the one described in #18 Thanks in advance. Happy coding!!!!

Mekala-palaniyappan avatar Aug 22 '18 14:08 Mekala-palaniyappan

No longer needed redirects. Just check #37.

z3nth10n avatar Mar 08 '19 03:03 z3nth10n

I still think it would be great to have a languages fallback system. Having this

en:
  title: Jekyll
  desc: Hello
  
fr:
  desc: Bonjour

would be greatbut something even better would be to also be able to get the french title if it doesn't exist in english.

However it would already be great to have it working for english as fallback

victorbnl avatar May 13 '21 19:05 victorbnl

@git-no that's neat but does not work when using multiple language files.

espen avatar May 06 '22 16:05 espen