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

Not generating custom asset when default_lang != first language #233

Open
george-gca opened this issue Feb 1, 2025 · 5 comments
Open

Not generating custom asset when default_lang != first language #233

george-gca opened this issue Feb 1, 2025 · 5 comments

Comments

@george-gca
Copy link
Collaborator

Here is the situation:

_config.yml

include: ["_scripts"]

languages: ["en-us", "pt-br"]
default_lang: "en-us"
exclude_from_localization: ["assets"]
lang_from_path: true
parallel_localization: false

_scripts/scripts.js.liquid

---
permalink: /assets/js/scriptsss.js
---
...

It correctly creates

ls _site/assets/js/
cookies.js  levenshtein.js  pwa.js  scriptsss.js  theme.js

ls _site/pt-br/assets/js/
scriptsss.js

Everything is fine, scriptsss.js was correctly created in the assets dir for every language.


Now, if I change only the default_lang in _config.yml to pt-br, this happens:

ls _site/assets/js/
cookies.js  levenshtein.js  pwa.js  theme.js

ls _site/en-us/assets/js/
scriptsss.js

Any idea why it doesn't create the file _site/assets/js/scriptsss.js?

@george-gca george-gca changed the title Not generating custom asset when default_lang != en-us Not generating custom asset when default_lang != first language Feb 1, 2025
@george-gca
Copy link
Collaborator Author

Update, when I change the order of the languages in the _config.yml file, like this:

_config.yml

languages: ["pt-br", "en-us"]
default_lang: "pt-br"

It works for pt-br

ls _site/assets/js/
cookies.js  levenshtein.js  pwa.js  scriptsss.js  theme.js

ls _site/en-us/assets/js/
scriptsss.js

but now, it doesn't work for en-us, like

_config.yml

languages: ["pt-br", "en-us"]
default_lang: "en-us"
ls _site/assets/js/
cookies.js  levenshtein.js  pwa.js  theme.js

ls _site/pt-br/assets/js/
scriptsss.js

Meaning, it only correctly generates the file if the default_lang is the first language in the list of languages. I don't know why.

@george-gca
Copy link
Collaborator Author

Since it works when the first language is the default_lang, I see 2 possible solutions:

  1. Check if this is something that can be fixed, meaning if the languages can be processed in any order without problem and how to do it
  2. Process default_lang first, then process all languages later, skipping the language if it is the default_lang.

How do you want to proceed with this?

@untra
Copy link
Owner

untra commented Feb 1, 2025

Great investigation! and excellent clues. defs this is interesting behavior.
I'm not sure why this could be happening, but a couple of thoughts:

  1. parallel_localization: false builds the site in the order of defined languages
    https://github.com/untra/polyglot/blob/master/lib/jekyll/polyglot/patches/jekyll/site.rb#L34

The list of all site languages to process is defined as all_langs = (@languages + [@default_lang]).uniq. Really the order should not matter with the built site defining all_langs , because the default_lang site still gets processed with separate logic. And with parallel_localization: true the site is built multithreaded and so there is no real order to which language is built first. However with parallel_localization: false the processed sites are defs built in order of the @languages. If this is the culprit, this can be fixed by reordering that line as all_langs = ([@default_lang] + @languages).uniq .

  1. coordinate_documents hook running for :site, :post_read is language order specific:
    the jekyll hook to coordinate documents by their file language is likely language order dependent.
    https://github.com/untra/polyglot/blob/master/lib/jekyll/polyglot/hooks/coordinate.rb#L3-L5

this process happens before site.prepare occurs. Although the true order is entirely by documents, if a document doesn't specify a lang it gets inferred from derive_lang_from_path(doc), or is associated with the site @default_lang.
https://github.com/untra/polyglot/blob/master/lib/jekyll/polyglot/patches/jekyll/site.rb#L148

all tests around this have the default_lang as the first language in the site configuration.

I'll try and think of more things. I can imagine some tests to write around these that could be easy to verify.

@george-gca
Copy link
Collaborator Author

Should I close this as completed?

@untra
Copy link
Owner

untra commented Mar 31, 2025

have you tried using the latest changes not yet released (run ./make.sh on the latest on main). I added a test that should verify this, but lets confirm; does the build work if the default_lang is not the first in languages?

languages: ["pt-br", "en-us"]
default_lang: "en-us"

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

No branches or pull requests

2 participants