Help Wanted from RegEx/Bash wizard(s) for AP website


I’m trying to make a GitHub Action that turns the translations files for the website into actually translated content. The Action needs to execute a command for each markdown file (website page) and in each language (so I’ll need to find a way to get a double for loop).

I want to create a bash array for the languages, based on the list of languages as defined in the website’s _config.yml file. The file contains the following line:

languages: [en, nl, de]

More languages could of course be added. For the foreseeable future we’ll probably have an array with only one value: en.

So, based on that line in that file, how do I create an array that I can use in bash? I guess there’s two parts:

  • what is the right RegEx to filter out each of the languages
  • how to turn the RegEx finds into a Bash array (I think I can use this in combination with grep instead of find)

Any help would be very welcome! :slight_smile:

Single loop I have so far

The code I currently have to create translated files for a specific section, in this case ‘general’:
cd _i18n/en/general && for file in *; do po2md $file --po-files ../../PO-files/site-general_nl.PO --save ../../nl/general/$file; done

Would you still need answers to these questions? I can not really see anything in the commit log suggesting any github action has been added.

Ideally one could use a tool capable parsing yaml to return the values, as the yaml syntax is not constrained to the format used now. It would be reasonable to expect this list of languages to fit one one line and thus be able to parse it with a regex, and practically it should suffice to use:

LANGUAGES=$( sed -n 's/,//g; s/^\s*languages:\s*\[\(.*\)]/\1/p' < _config.yml )

Which would make $LANGUAGES contain a space separated string such as: en nl de.

Unless I’m missing something, you don’t. As all languages will always be simple alphabetic strings, there is really no need to use arrays. Use for to loop over words, otherwise it’ll only become complex.

How about something like this:

#!/bin/sh -eu
LANGUAGES=$( sed -n 's/,//g; s/^\s*languages:\s*\[\(.*\)]/\1/pi' \
    <'_config.yml' )
for SECTION in 'general' 'contribute'; do
  pushd "_i18n/en/${SECTION}/"
  for L in ${LANGUAGES}; do
    for FILE in *; do
      if [ -e "../../PO-files/site-general_${L}.PO" ]; then
        po2md ${FILE} --po-files "../../PO-files/site-general_${L}.PO" \
            --save "../../${L}/general/${FILE}"
        echo "Warning missing ${SECTION} for ${L}" >&2


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