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 lang.HasTranslation #10538

Open
regisphilibert opened this issue Dec 14, 2022 · 1 comment · May be fixed by #10539
Open

Add lang.HasTranslation #10538

regisphilibert opened this issue Dec 14, 2022 · 1 comment · May be fixed by #10539

Comments

@regisphilibert
Copy link
Member

regisphilibert commented Dec 14, 2022

The problem

Currently it is not possible to know if a translation key is available in a site's language.

Many themes rely on open contributions to maintain their localization. If a a new string needs to be added or and old one edited, maintainers need to either:

  1. Wait for localization contributor to translate it before releasing.
  2. Leave an untranslated string (printed as the default language's string) and hope for contributors to translate it later.

2. Will add this untranslated string to every project updating the theme.

Current workaround is rather clumsy (assumes default lang is en):

{{ $read_more := i18n "read_more_about_entry" }}
{{ if ne site.LanguageCode "en" }}
  {{ if eq $read_more "read more about this entry" }}
    {{ $read_more = i18n "read_more" }}
  {{ end }}
{{ end }}
<a href="{{ .RelPermalink }}"> {{ $read_more }}</a>

Proposal

Introduce a new method on the lang object or the site.Lang object which tests the existence of a translation key and returns a boolean.

{{ $read_more := "read_more_about_entry" }}
{{ if not (site.Lang.HasTranslation "read_more_about_entry") }}
  {{ $read_more = "read_more" }}
{{ end }}
<a href="{{ .RelPermalink }}"> {{ i18n $read_more }}</a>
@bep bep changed the title Add lang.HasTranslation Add site.Language.HasTranslation Dec 14, 2022
@bep bep changed the title Add site.Language.HasTranslation Add langs.HasTranslation Dec 14, 2022
@bep bep changed the title Add langs.HasTranslation Add lang.HasTranslation Dec 14, 2022
@bep bep added this to the v0.109.0 milestone Dec 14, 2022
@bep bep linked a pull request Dec 14, 2022 that will close this issue
bep added a commit to bep/hugo that referenced this issue Dec 14, 2022
bep added a commit to bep/hugo that referenced this issue Dec 14, 2022
bep added a commit to bep/hugo that referenced this issue Dec 14, 2022
@bep bep modified the milestones: v0.109.0, v0.111.0 Jan 26, 2023
@bep bep modified the milestones: v0.111.0, v0.112.0 Feb 15, 2023
@bep bep modified the milestones: v0.112.0, v0.113.0 Apr 15, 2023
@bep bep modified the milestones: v0.113.0, v0.115.0 Jun 13, 2023
@bep bep modified the milestones: v0.115.0, v0.116.0 Jun 30, 2023
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 5, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@jmooring
Copy link
Member

Revisiting this, the implementation of lang.HasTranslation in #10539 would be nice to have. I just took that for a spin again, and it works great for the use cased described in #11782.

The PR needs to be rebased, but other than that it looks good.

@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants