Skip to content

Add lang.HasTranslation #10538

Open
Open
@regisphilibert

Description

@regisphilibert

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>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions