How can I flag a page that is a fill-in from the base language?

I am using module.mounts to fill in missing pages in a given language from existing pages in the base language.

Is there a .Page flag that can tell me if a “fill-in” has occurred?

.Page.IsTranslated and .Page.Translations don’t help, as they assume that the pages I have filled in have been translated: they have not. They are listed in the current language, but the content has been pulled from the base.

.Page.Language simply returns the filled-in language.

Right now, I am forced to add a front-matter parameter (translated: true) to every translated page. Could we set a value in that module loop, maybe .Page.ContentLanguage, so that we know the source of the back fill? That might require a new param in the module map, as right now we are simply connecting source and target folders.

Second best is a boolean, .Page.IsFilledIn or (perhaps confusingly) .Page.IsNotTranslated. Either one will allow me to programmatically alter pages to show/hide text, and offer instructions/options to the reader.

Maybe there is a clever workaround to this already. I tried page orig/curr languages, but by the time I get there, they are already derived.

Thanks!

I didn’t quite understand the use case (need) for this from reading the above. Can you clarify?

This is clumsy, but…

{{ with .File }}
  {{ strings.TrimPrefix hugo.WorkingDir .Filename }}
{{ end }}

This will return things such as:

/content/nl/test-1.md
/content/en/test-2.md
/content/nl/test-3.md

I’d still like to understand the use case, and how it might relate to the work-in-progress on content dimensions.

Thanks, I’ll check that out. Platforms are works-in-progress, and what is clumsy today is smooth tomorrow.

The app I am working on is a global community clearinghouse, whose content is mostly elaborated in US/UK English. Based on local and cultural priorities, non-English-speaking affiliates of this organization will translate pages for their in-country use. Until they do, however, all of the curated base-language content should be available. I’ll share my repo some day when the kids are not hammering at the door (as they are now) (it is bedtime, really it is). Meanwhile, the test server page I just hacked into shape is here: parent “singing” page, sidebar “songs” collected and sorted, which can be toggled in context, or opened using the “single” template using the link icon next to the song.

Every time an English-language page is offered for a non-English translation (using the fill-in module method), I need to know it. Knowing has not been translated, but filled in, I add an i18n-resourced message inviting the reader to click to “request translation” into their local language.

In a number of situations, subfolder pages are presented in list format in their “parent” page. This list sorts by sorting index then by alpha, but I needed to have that “translated” flag so that I always sort the local language first.

All in all, if I have a loop somewhere that is injecting these pages into other language folders in public or docs, it seems natural for me to stamp the injected page as “having been injected”. There’s got to be an inner loop in there somewhere. It would make life so much easier.

These are solid use cases. Thanks.

This works

 
  {{ $base := .Site.Sites.Default }}
  {{ $src := index (split (lower (strings.TrimPrefix hugo.WorkingDir .File.Filename)) "/") 2 }}
  {{ $translated := ne $src $base.Language.String }}

UPDATE: $base.Language doesn’t resolve as type STRING, so the compare operation does not work as expected.

1 Like

Remember that some pages may not be backed by a file (e.g., a term page), so you should code defensively with something like:

{{ with .File }}
  {{ strings.TrimPrefix hugo.WorkingDir .Filename }}
{{ end }}

Good, thank you. In our case, I think that all of the structures where this is used will be file-backed. Nonetheless, I’ll modify the script to be emptiness-proof, so that 5 years (or 5 months) from now, we’re not unpleasantly surprised.

I think this does it:


  {{ $base := .Site.Sites.Default }}
  {{ $src := cond .File (index (split (lower (strings.TrimPrefix hugo.WorkingDir .File.Filename)) "/") 2) "" }}
  {{ $translated := ne $src $base.Language.String }}

Until I start using multiple languages for fill-in, I guess…

UPDATE: $base.Language doesn’t resolve as type STRING, so the compare operation does not work as expected.

Use .Language.Lang instead of the undocumented .String method.

1 Like
{{ $base := .Site.Sites.Default }}
  {{ $src := cond .File (index (split (lower (strings.TrimPrefix hugo.WorkingDir .File.Filename)) "/") 2) "" }}
  {{ $translated := ne $src $base.Language.Lang }}

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.