Skip to content

Instantly share code, notes, and snippets.

@Lemmings19
Last active April 12, 2017 22:46
Show Gist options
  • Save Lemmings19/e3a46cf15c69cf3e39713bc54f737be8 to your computer and use it in GitHub Desktop.
Save Lemmings19/e3a46cf15c69cf3e39713bc54f737be8 to your computer and use it in GitHub Desktop.
Generating an updated PHP translation file using gettext

Simple Instructions:

Run the command.

Explanations:

  1. xgettext will parse a file and look for strings which are wrapped in _(). It will output those strings to a .po file for translations (default filename = messages.po).
  2. The find command will cause xgettext to parse all of the files which find returns rather than just parsing a single file.
  3. --join-existing will merge the results to an existing message.po file in the same output directory.
    • --join-existing shouldn't be used if a messages.po file doesn't already exist in the location which your output points to.

Invocation documentation for xgettext.

find /var/www/project/source -iname "*.php" -o -iname "*.phtml" | xargs xgettext --output-dir=/var/www/project/source/application/languages/ --language=PHP --no-wrap --default-domain='translation-template' --copyright-holder='Company' --msgid-bugs-address=support@company.com --join-existing
@Lemmings19
Copy link
Author

Running this on OSX, you might need to install gettext:
http://stackoverflow.com/a/33896321/1196517

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment