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

Use default language when no language set #3069

Merged
merged 2 commits into from
Mar 12, 2018
Merged

Use default language when no language set #3069

merged 2 commits into from
Mar 12, 2018

Conversation

bobd91
Copy link
Contributor

@bobd91 bobd91 commented Mar 11, 2018

Use default language when no language set, or there is no translation for specified language

If no language is set in _config, or the theme has no language file for the one set, then the translation data is chosen in indeterminate manner as it is taken from a list of all available translations returned by hexo.theme.i18n#list().

The changes to lib/plugins/filter/template_locals/i18n.js use i18n.languages in preference to config.language and i18n.list() as this provides an array of configured languages with 'default' on the end. This ensures that if no language is set or the language cannot be found then then default translation will be used.

The changes to test/scripts/filters/i18n_locals.js set i18n.languages rather than config.language as the original test code did not set the 'default' language correctly.

Added two tests

  • use config by default - with no languages, default language should be used
  • use config by default - with unknown language, default language should be used

Both of the new tests fail on the current release but pass with the changes in the pull request.

This is a fix for #1125

Or there is no translation for specified language
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 97.251% when pulling 057229c on bobd91:default-language into 940495c on hexojs:master.

@coveralls
Copy link

coveralls commented Mar 11, 2018

Coverage Status

Coverage decreased (-0.002%) to 97.274% when pulling 65301af on bobd91:default-language into 940495c on hexojs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 97.251% when pulling 057229c on bobd91:default-language into 940495c on hexojs:master.

@bobd91
Copy link
Contributor Author

bobd91 commented Mar 11, 2018

LOL, if you remove code then the coverage % goes down even though all of the code you have changed is covered!
I only removed the code in the first place as my original changes caused a particular branch to never be executed (code run if variable is not an array on something that is now always an array).
Feeling frustrated with coveralls.

@JLHwung JLHwung merged commit f9230cc into hexojs:master Mar 12, 2018
@JLHwung
Copy link
Collaborator

JLHwung commented Mar 12, 2018

Good catch and thanks!

@ivan-nginx
Copy link

ivan-nginx commented Apr 4, 2018

If no language is set in _config, or the theme has no language file for the one set, then the translation data is chosen in indeterminate manner as it is taken from a list of all available translations returned by hexo.theme.i18n#list().

Not indeterminate manner, but take first catched language in themes/languages directory. So, if first language will de.yml, it's will set DE language if this 2 cases above will reproduce.

For now this pull create 1 additional bug in NexT theme: if 2 cases above will reproduce and default.yml not exists in themes/languages directory, no one language will be selected. So, for now it's mean need to create 1 additional symlink or rename en.yml on default.yml, but before this pull this bug was solved just by renaming en.yml on _en.yml.

Breaking Changes for most Hexo themes

This pull with 2 cases above will brake many themes in which default.yml in themes/languages not exists. There is the list:

So, this bugfix now produce ≈ 80% breaking changes for all Hexo themes.
@JLHwung, @NoahDragon, please, test pulls like that before merge for all possible breaking changes, Thank's!

Possible fixes for this changes

This ensures that if no language is set or the language cannot be found then default translation will be used.

Use first language in list (instead of this) if default.yml file not exists.

@bobd91
Copy link
Contributor Author

bobd91 commented Apr 4, 2018

Not indeterminate manner, but take first catched language in themes/languages directory.

On your system maybe, but the order of the language files is dependent upon the order that Node's readdir function provides. It is well documented that Node's readdir on Windows does not provide a sorted list and even on Linux the underlying readdir C function makes no promises on ordering.

@ivan-nginx
Copy link

ivan-nginx commented Apr 4, 2018

Node's readdir on Windows does not provide a sorted list and even on Linux the underlying readdir C function makes no promises on ordering.

It's alphabetical or vice-versa. Will be load first or last language. But it's can't load random language, i think. So, it can't be called indeterminate manner.


Anyway, default platform is Linux and as i say here, this fix for now worse then was before.

@bobd91 bobd91 deleted the default-language branch April 4, 2018 13:32
ivan-nginx added a commit to theme-next/hexo-theme-next that referenced this pull request Apr 9, 2018
After complete fix with language file selection in Hexo we can use old method with no bugs.

Issue: hexojs/hexo#3108
Fix 1: hexojs/hexo#3069
Fix 2: hexojs/hexo#3110
@curbengh curbengh mentioned this pull request Sep 28, 2019
@NoahDragon NoahDragon mentioned this pull request Sep 28, 2019
53 tasks
sslogan666 pushed a commit to sslogan666/sslogan666.github.io that referenced this pull request Jun 12, 2021
After complete fix with language file selection in Hexo we can use old method with no bugs.

Issue: hexojs/hexo#3108
Fix 1: hexojs/hexo#3069
Fix 2: hexojs/hexo#3110
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

Successfully merging this pull request may close these issues.

4 participants