Can data files be translated?

We have english words and phrases in some /data/---.yaml files. Can these be translated? If so how? We’re using the i18n folder for string translation but the data files contain more info needed for our site like arrays and images etc

Thanks

Yes, but the data feature is deliberately not a first class citizen of the i18n country, so you’ll have to make up the model yourself, i.e. maybe:

/data/en
/data/fr

...

$myData := (index .Site.Data .Site.Lang)
1 Like

Do any up coming milestones after 19 include plans to support this translation?

No… But then I think you overestimate the “Hugo long term plan”. But in my head right now, the content in /data is mostly language agnostic – and if it contains something that needs translation:

{{ i18n .Site.Data.myTextKey . }}

Or something.

Hi, Bep
I was tried above logic for translating data content yaml file.
Here is my code.

      {{ range $index, $element := sort .Site.Data.features .Site.Language "weight" }}
            <div class="col-md-3 col-sm-6">
                <div class="feature-item">
                    <div >
                        <img src="{{ .icon }}">
                    </div>
                    <h4>{{ $element.name }}</h4>
                </div>
            </div>
     {{ end }}

-folder structure

        - data
             - features
                  - en
                  - fr
             - other
                  - en
                  - fr
                  ......

Above code refers on feature data elements
Compile work correctly.
But can’t load data elements.
Please let me know kindly.
Thanks

1 Like

Hi Tania,

have a look at my site, where I successfully achieved translation of data files. Hopefully you’ll get some insight with it :slight_smile:

See also: Data with multilanguage

4 Likes

Thanks for your fast response.
Working.
Regards.