Skip to content

Instantly share code, notes, and snippets.

@justinas
Created March 15, 2016 10:10
Show Gist options
  • Save justinas/ff7089e91ca2035c7199 to your computer and use it in GitHub Desktop.
Save justinas/ff7089e91ca2035c7199 to your computer and use it in GitHub Desktop.
Running xgettext on a Rust file
$ cat a.rs; xgettext a.rs -o -
fn main() {
catalog.gettext("Cucumber");
catalog.ngettext("Cucumber", "Cucumbers", 42);
catalog.pgettext("a vegetable", "Cucumber");
catalog.npgettext("a vegetable", "Cucumber", "Cucumbers", 42);
gettext!("Hi");
}
xgettext: warning: file 'a.rs' extension 'rs' is unknown; will try C
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-03-15 12:09+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
#: a.rs:2 a.rs:3
msgid "Cucumber"
msgid_plural "Cucumbers"
msgstr[0] ""
msgstr[1] ""
#: a.rs:4 a.rs:5
msgctxt "a vegetable"
msgid "Cucumber"
msgid_plural "Cucumbers"
msgstr[0] ""
msgstr[1] ""
@ogoffart
Copy link

ogoffart commented Dec 9, 2018

I'm highjacking this gist to advertise the xtr crate https://github.com/woboq/tr

Using the same a.rs as in the original:

$ RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo install xtr
[...]
$ xtr a.rs -o a.pot
$ cat a.pot
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-12-09 12:12+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: a.rs:2 a.rs:3
msgid "Cucumber"
msgid_plural "Cucumbers"
msgstr ""

#: a.rs:4 a.rs:5
msgctxt "a vegetable"
msgid "Cucumber"
msgid_plural "Cucumbers"
msgstr ""

#: a.rs:7
msgid "Hi"
msgstr ""

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