Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

I18n for site and Front Matter configurations #125

Merged
merged 14 commits into from Jan 19, 2022

Conversation

pgoltsev
Copy link
Contributor

@pgoltsev pgoltsev commented Jul 18, 2018

Rationale

I thought it would be very useful if site properties, which are defined in _config.yml->site map such as site.description, site.author, site.title etc. and some Front Matter's properties, may be transparently translated without explicitly using LocalizeTag. In many cases it could be very convenient and in some cases usage of the tag is just impossible. For example, transparent translation allows do not overwrite original theme files where site.title and similar are used just to be able to translate them. And it is impossible to apply translation tag on these properties in third-party plugins such as jekyll-feed. This plugin has 'feed.xml' template that could not be overrode in a simple way (and actually it isn't needed usually). Thus, transparent translation allows do not change any files at all because properties will be already translated when they will be put into templates.

Backward Compatibility

In order to preserve backward compatible behavior I introduced new property 'translate_props' that contains names of properties which must be transparently translated. In case if 'translate_props' is not defined no translation is performed which is default and the current behavior.
This implementation allows to define transparent translation in _config.yml as

translate_props: ["author", "description", "title"]

And appropriate properties could be defined as paths to translation such as

title: global.title
author: global.author
description: global.description

Then every file _i18n/lang.yml must contain these paths

global:
  author: Pavel Goltsev
  title: My Blog
  description: Welcome to my personal blog

The same functionality was added for Front Matter of a page. Thus, in order to translate any property inside of Front Matter this property must be included into 'translate_props' of this Front Matter. For example, if we need to translate 'title' in About page, we can put these data into about.md

title: about.title

translate_props: ["title"]

And add 'about.title' to every i18n/lang.yml

about.title: About

Extra Notes

I tested it against my current blog and it works fine. Likely, unit tests would be preferable against manual testing. But since I'm not good at Ruby at all (actually, I just met it first time when I wanted to make these changes) I have problems with creating them. I would be very thankful if you could either add them by yourself or share docs on me how to do it.
Although it is just a good implementation of Proof-Of-Concept it could be merged into upstream as is. But of course any improvements, including naming of variables, changes in architecture etc., are welcome.

Cheers!

It was needed to remove duplicate code that resided in
'LocalizeTag.render' method and newly created
'SiteLocalize.translate_key'.
Correct handling of empty property name, a name defined as not a string
and a name consists of only spaces has been added.
Also minor refactoring in favor of little optimization has been applied.
Class 'SiteLocalize' was renamed to 'Localizer' and reduced to
a common implementation, not only for site configuration localization.
A property which stores properties that must be localized renamed
to 'localize_props'.
@pgoltsev pgoltsev changed the title Site properties localization I18n for site and Front Matter configurations Jul 20, 2018
Method 'localize_to' of Localizer renamed to 'translate_to'.
Name of a property for translation renamed from 'localize_props' to
'translate_to'.
A bug in 'serve' mode of Jekyll was fixed. The bug was in empty strings
once site rebuilt because of an attempt to translate already translated
strings once again.
Class Localizer has been removed due to redundancy and has been replaced
with function 'translate_props'.
New class TranslatedString was instroduced to store a key within
translated value and distinguish key and translated value.
@kurtsson
Copy link
Owner

Hi @pesh1983. The main administrator @Anthony-Gaudino, has disappeared so we are in a bit of a sad state here. I still have access to the Ruby Gem and can release new versions but I do not use any Jekyll sites and have no way of verifying PRs. In short this project really need a new owner, is that you? Or can you atleast verify all PRs so I can merge and make a release?

@pgoltsev
Copy link
Contributor Author

Hi @kurtsson,
Sad to read it. I hope nothing serious happened to him.
Actually, I don't think I'm fit for a role of new owner. I'm not ruby developer (I met this language while preparing changes in my PR) and I'm not sure I can find free time for the project. I can try to verify all PR in order you will be able to release new version but I can't promise it will be fast. Let me know if it is fine.
Cheers!

@kurtsson
Copy link
Owner

Hi @kurtsson,
Sad to read it. I hope nothing serious happened to him.
Actually, I don't think I'm fit for a role of new owner. I'm not ruby developer (I met this language while preparing changes in my PR) and I'm not sure I can find free time for the project. I can try to verify all PR in order you will be able to release new version but I can't promise it will be fast. Let me know if it is fine.
Cheers!

That would be super helpful, thank you!

@shushugah
Copy link
Collaborator

Any update on the state of maintenance? I would be interested in helping out with PR's because I am using this gem myself and need new features/improved documentation anyways.

@kurtsson
Copy link
Owner

kurtsson commented Jun 20, 2019

Any update on the state of maintenance? I would be interested in helping out with PR's because I am using this gem myself and need new features/improved documentation anyways.

Not really, I still own the gem but @Anthony-Gaudino is completely gone. I guess I could ask Github to transfer the project back to me but I'm not using the plugin myself so I rather not be the sole maintainer. But if someone is willing to pick it up, Im very grateful. Is that you @shushugah?

Right now I'm approving PRs tested by the community and releasing new versions when asked for.

@shushugah
Copy link
Collaborator

I took the time to reflect on my time availability and technical expertise. I've never maintained an OS project before but would be very excited to take this challenge. I would ask for a transition/collaborative period, but am eager to take off some of the load from you.

@kurtsson
Copy link
Owner

I took the time to reflect on my time availability and technical expertise. I've never maintained an OS project before but would be very excited to take this challenge. I would ask for a transition/collaborative period, but am eager to take off some of the load from you.

Cool! I also managed to get the ownership back of the project, so now I can add you as an admin for starters.

@kurtsson
Copy link
Owner

Is this still valid? If not, I think I close it

@pgoltsev
Copy link
Contributor Author

pgoltsev commented Dec 4, 2021

It is, I've updated the PR with the latest changes from the main branch.

@kurtsson
Copy link
Owner

kurtsson commented Dec 7, 2021

It is, I've updated the PR with the latest changes from the main branch.

Is it verified? Should we release it?

@pgoltsev
Copy link
Contributor Author

pgoltsev commented Jan 9, 2022

Yes, it is verified and can be merged.

@kurtsson kurtsson merged commit 4a84260 into kurtsson:master Jan 19, 2022
@kurtsson
Copy link
Owner

@pgoltsev Should I push this as 1.7.1 release or 1.8.0?

@pgoltsev
Copy link
Contributor Author

pgoltsev commented Jan 19, 2022

@kurtsson I would release it under 1.8.0 because it is a new feature. Thank you

@team-community
Copy link

In the new version 1.8.0 I get the error: "jekyll "Missing i18n key:" But the translation string exists in the .yml file.

@shushugah
Copy link
Collaborator

@team-community just the gem update and no other changes?

@team-community
Copy link

@team-community just the gem update and no other changes?

Hello. All right. Only Gem has been updated.

In my case, it's obviously related to jekyll paginate v2. Because when generating "Page 2", this plugin thinks that there is a empty string.
Version 1.7.0 works.

@pgoltsev pgoltsev deleted the site-properties-localization branch May 20, 2022 07:30
@pgoltsev
Copy link
Contributor Author

I will check it soon. Thank you.

@raysworld
Copy link

@team-community just the gem update and no other changes?

Hello. All right. Only Gem has been updated.

In my case, it's obviously related to jekyll paginate v2. Because when generating "Page 2", this plugin thinks that there is a empty string. Version 1.7.0 works.

Hi, @pgoltsev, I encountered the same issue. The Front Matter I am using is:

---
layout: newsv2
title: titles.news.all_news

permalink: /news/all_news/

pagination: 
  enabled: true
  permalink: /:num/
  sort_field: 'date'
  sort_reverse: true

translate_props: ["title"]
---

using Version 1.8.0, I got the following error:

Missing i18n key: cn:titles.news.all_news - page 2
Using translation '' from default language: en
bundler: failed to load command: jekyll (/home/rui/.gems/bin/Jekyll)

using Version 1.7.0, no error is reported, but the titles will not be translated.

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

Successfully merging this pull request may close these issues.

None yet

5 participants