How can I translate the keys of a .yml (YAML) file?

I’m trying to set up translation for a website that I’ve built using MkDocs. A part of MkDocs is the inclusion of .nav.yml files for navigation, which uniquely need the keys translated rather than the values.

How can I get Crowdin to recognize that I need the keys translated?! I’m importing through Github right now and I’ve failed to wrap my head around it. I tried to set up what another user did, editing the crowdin.yml file to somehow change .yml files to .txt, but it didn’t work. Any help would be greatly appreciated.

Hi @chmess !

The core issue is that Crowdin treats YAML keys as static identifiers and only makes values translatable, so for .nav.yml files where the keys are the actual navigation labels, the standard YAML parser simply won’t pick them up.

The fix could be to tell Crowdin to treat the file as plain text using the dest and type parameters. This makes Crowdin import the file line by line, which means everything becomes translatable, including the nav labels.

Here’s the exact config for your crowdin.yml:

files:
  - source: /docs/.nav.yml
    translation: /docs/.nav.%two_letters_code%.yml
    dest: /docs/.nav.txt
    type: txt
    preserve_hierarchy: true

A couple of things to check:

  • preserve_hierarchy: true is required when using dest - without it, the setup won’t work
  • Make sure the source path matches the exact location of your .nav.yml in the repo

Let me know how it works for you!

At first, I was disappointed that it didn’t work… But suddenly, after I put that chunk of configs above my preexisting ones, it works! I can now edit the .nav.yml file as if it were .txt and export it to .nav.yml! Thanks so much!

(I did have to slightly change the code, since I use a folder-based localization system, where my source files are in /docs/en/ and my translations are in /docs/xx/. Just saying in case someone else stumbles across this!)

I am glad to hear that you got it working :grinning_face:

Also, thank you for sharing the adjustment you made for your folder-based localization system. Detailing how you routed your source files and translations is incredibly helpful for other users who might stumble across this thread with a similar directory structure :slight_smile: