kurtsson / jekyll-multiple-languages-plugin

I18n support for Jekyll and Octopress
MIT License
927 stars 202 forks source link

Option to put default language in subfolder also puts non-translated static contents (img etc.) in subfolder #187

Open sceee opened 3 years ago

sceee commented 3 years ago

In the past, I used the setup I also described here: Have a default language be put to root and in a separate language folder:

index.html // English index
en/index.html //English index - equals root index.html
de/index.html //German index

Since #170 , it seems there is no way to put the default language to a subfolder but keep static assets in the root. E.g.

/img/test.jpg
/en/index.html
/de/index.html

It seems that everything specified in

exclude_from_localizations: ["js", "img", "css", "fonts"]

is still put in the default languages's folder:

/en/index.html
/en/img/test.jpg
/de/index.html

Of course, I read in the docs that those files should be referenced using a prepend like

<link rel="stylesheet" href="{{ "/css/bootstrap.css" | prepend: site.baseurl_root }}"/>

Unfortunately, this only works well for html/md files.

In my case, I reference font files (.woff) in sass files - after some googling, it turned out that you cannot simply use {{ "/fonts/myfont.woff" | prepend: site.baseurl_root }} in sass files as there are some restrictions that this can only be used in a top-level sass file.

So overall, it seems very complicated for a fairly simple thing - I just want all my static assets be on the root so I have a structure like this:

/img/test.jpg
/en/index.html
/de/index.html

and can just reference those files with a regular <link rel="stylesheet" href="/css/bootstrap.css"/>.

Is there any possibility to still configure the plugin to produce an output like this with the 1.7 release?

g-konst commented 3 years ago

With following settings in _config.yml:

languages: ["en", "ru"]
exclude_from_localizations: ["js", "images", "assets"]
default_locale_in_subfolder: true

I get next _site structure:

/images/..
/js/..
/assets/css/..
/en/index.html
/ru/index.html

So it seems to work.

If you set default_locale_in_subfolder to false, it will be the same except for the en folder, because these files will be at the root:

/images/..
/js/..
/assets/css/..
/index.html
/ru/index.html
sceee commented 3 years ago

@g-konst which version are you using?

With 1.6.1, the issue occurs as described.

g-konst commented 3 years ago

@g-konst which version are you using?

With 1.6.1, the issue occurs as described.

Latest, 1.7

sceee commented 3 years ago

So even if I use 1.7.0 with your config settings, it's not working: Output directory then only contains de en and misses css etc. directories.

Config is:

languages: ["en", "de"]
default_locale_in_subfolder: true
exclude_from_localizations: ["public", "js", "img", "css", "fonts"]
g-konst commented 3 years ago

@sceee check this please. https://www.youtube.com/watch?v=s_8KA6FyLjo

sceee commented 3 years ago

@g-konst thanks for the video but it seems to behave differently on my side. I don't know why it's working on your side but not on mine. But since two other people also upvoted this, I guess they also ran into this issue.

In the end, it just looks like this if I use 1.7.0: image

g-konst commented 3 years ago

Try disabling all themes or plugins, perhaps one of them overwrites some of the config options. Or to put it another way, try building your project using a different OS (maybe in docker).

Heanthor commented 2 years ago

Bumping with a related fix: I also ran into this same problem, however I am using a custom source directory. With the config setting source: ./src I had to also include that path in the exclude options:

exclude_from_localizations: ["src/images", "src/css"]
figgles commented 1 year ago

I've configured my site to do exactly what you do with 1.8.0

/en/index.html
/es/index.html
/images/example.jpg

This feature isn't broken. Since this is > 2 years old, I suggest closing the issue.

LorenzoDelpi commented 1 year ago

@figgles can you share your environment details? I am trying to replicate the solution but it does not work with my env.

figgles commented 1 year ago

@LorenzoDelpi Gemfile

source "https://rubygems.org"
gem "jekyll", "~> 4.3.2"
group :jekyll_plugins do
    gem 'jekyll-multiple-languages-plugin'
end
platforms :mingw, :x64_mingw, :mswin, :jruby do
  gem "tzinfo", ">= 1", "< 3"
  gem "tzinfo-data"
end
gem "wdm", "~> 0.1.1", :platforms => [:mingw, :x64_mingw, :mswin]
gem "http_parser.rb", "~> 0.6.0", :platforms => [:jruby]

_config.yml

# Build settings
plugins:
  - jekyll-multiple-languages-plugin

# Localization
languages: ["en", "es"]
default_locale_in_subfolder: true
exclude_from_localizations: ["assets", "images", "favicon.ico"]

exclude:
  - doc/
  - assets/sass