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

Add Customized Slug or Translation for Authors #3633

Open
1 of 3 tasks
ChenZheChina opened this issue Jul 1, 2022 · 0 comments
Open
1 of 3 tasks

Add Customized Slug or Translation for Authors #3633

ChenZheChina opened this issue Jul 1, 2022 · 0 comments

Comments

@ChenZheChina
Copy link

ChenZheChina commented Jul 1, 2022

Requested Feature: Add Customized Slug or Translation for Authors

Related Area: authors, categories, tags, slug, unidecode, translatable

Do you want to contribute this yourself as a pull request? (don’t worry about it if you don’t want to/can’t — someone else can take care of it)

  • Yes, I have already written code for it (link if available and feasible)
  • Yes, I don’t have code ready yet (that’s okay!)
  • No (that’s okay too!)

conf.py

AUTHOR_CUSTOMIZED_SLUGS = {
    "en": {"Yamada Taro": "yamada-taro"},
    "zh_cn": {"山田太郎": "yamada-taro"},
    "ja": {"山田 太郎": "yamada-taro"},
    "ko": {"야마다 다로": "yamada-taro"},
}

plugins/task/authors.py

    def get_path(self, classification, lang, dest_type='page'):
        """Return a path for the given classification."""
        if self.site.config['SLUG_AUTHOR_PATH']:
            # Modified
            if 'AUTHOR_CUSTOMIZED_SLUGS' in self.site.config and \
                lang in self.site.config['AUTHOR_CUSTOMIZED_SLUGS'] and \
                classification in self.site.config['AUTHOR_CUSTOMIZED_SLUGS'][lang]:
                slug = self.site.config['AUTHOR_CUSTOMIZED_SLUGS'][lang][classification]
            else:
                slug = utils.slugify(classification, lang)
        else:
            slug = classification
        return [self.site.config['AUTHOR_PATH'](lang), slug], 'auto'

Does this feature affect backwards compatibility? If yes, in what way?

Probably not. Just like post titles, user could choose to use or not to use customized slugs. Nikola should work as usual, if a user chooses not to use customized slugs. But I am not sure about translatable strings.

Rationale and full description: (why should it be added to Nikola?)

There is a very complicated issue in romanizing / slugifying Japanese. See Japanese Kanji is transliterated as Chinese in Frequently Asked Questions of Unidecode at https://github.com/avian2/unidecode

Due to the reason above, I found it difficult to write authors in Japanese. Of course I can write their names in English (romanization), but it’s just not perfect.

On the other hand, if I write their names in Japanese, their names will be either slugified using Chinese pronunciations (e.g. 山田太郎 -> shan-tian-tai-lang), which is totally wrong, or kept intact as Japanese, which causes %-escaped URLs.

To solve the issue, I have two suggestions.

  1. Add customized slug for authors. If we can give an author called 山田太郎 a customized slug yamada-taro, then we can get a correct, simple URL yamada-taro (generated from customized slug), while seeing their real name in Japanese (the author name set in posts or BLOG_AUTHOR) in HTML.
  2. Add translatable string for authors. If we can give an author called Yamada Taro a translation 山田太郎, then we can get a correct, simple URL yamada-taro (generated from Yamada Taro, the name set in posts or BLOG_AUTHOR), while seeing their real name in Japanese (generated from translated string) in HTML.

PS: Categories and tags in Japanese have similar issues, as you can see here https://org-technology.com/categories/index.html (科学技術計算 is slugified as ke-xue-ji-shu-ji-suan, instead of kagaku-gijutsu-keisan), but I haven’t looked into it so I’m not sure if there is already a solution for categories and tags.

Update: I have implemented customized slugs for authors. It seems to be the easier way of two, and it works fine for me.

@ChenZheChina ChenZheChina changed the title Allow Customized Slug or Translation for Authors Add Customized Slug or Translation for Authors Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant