Using POEdit — only search for strings in specific domain

前端 未结 2 1859
一个人的身影
一个人的身影 2021-01-12 11:47

I have created a WordPress theme that I wish to translate.

Inside my theme I use some translations from woocommerce (i.e.

2条回答
  •  渐次进展
    2021-01-12 12:29

    The best solution would be if gettext or Poedit were able to restrict the translations to a certain domain. As Václav points out, this is not possible.

    A workaround might be to postprocess the my-text-domain.pot or *.po files and remove all strings that are actually from other plugins like woocommerce:

    #!/bin/bash
    
    # DRY_RUN="echo"
    DRY_RUN=""
    MY_DOMAIN="my-text-domain"
    
    for PO in *.po; do
      echo "Removing other domains from file: $PO"
      # OTHER_DOMAINS are all the domain that are not MY_DOMAIN
      OTHER_DOMAINS=`grep "# @ " $PO  | grep -v $MY_DOMAIN | sort | uniq | grep -o '\w*'`
      for OTHER_DOMAIN in $OTHER_DOMAINS; do
        echo "  Removing ${OTHER_DOMAIN}..."
        # Replace ever "foreign" strings with a linebreak
        # Begins with "# @ OTHER_DOMAIN" and ends with an empty line
        $DRY_RUN perl -0777 -i -pe "s/# @ ${OTHER_DOMAIN}\n.+?\n\n//smg" $PO
      done
    done
    

提交回复
热议问题