What is this ?
SQL interface for po(gettext) files.
Motivation
Use po file as a database. Can be useful for cli tools, UI interfaces, data exploration, also for fun.
Supported SQL
SELECT
UPDATE
SET
WHERE
AND
OR
NOT
COUNT
LIKE
LIMIT
Available columns
msgid, msgstr, msgstr[0-9], msgctxt, msgid_plural
Examples
As database:
;// open current directory as dbconst db = '.'; // catalog is a table points to catalog.po in './'const messages = dbconsole; // 42
As table:
;// open in memory data as a tableconst table = fs; // table name is irrelevant in select clauses except 'table' is a reserved word// get all untranslated recordstable); // [{ msgid: ' в категории %s',// msgctxt: null,// references: [ 'myproj/lib/title.py:959' ],// msgid_plural: null,// msgstr: [ '' ],// comments: [],// extractedComments: [],// flags: { 'python-format': true },// obsolete: false,// nplurals: 3 },// ....//]
Compound statements
// get all untranslated plural stringstable);
LIKE
table// [ { msgid: ' Продажа, поиск, поставщики и магазины, все цены',// msgctxt: null,// references: [ 'myproj/lib/title.py:1014' ],// msgid_plural: null,// msgstr: [ ' Продаж, пошук, постачальники та магазини, всі ціни' ],// comments: [],// extractedComments: [],// flags: {},// obsolete: false,// nplurals: 3 },
Advanced LIKE for case insensitive search
table// [ { msgid: ' Продажа, поиск, поставщики и магазины, все цены',// msgctxt: null,// references: [ 'myproj/lib/title.py:1014' ],// msgid_plural: null,// msgstr: [ ' Продаж, пошук, постачальники та магазини, всі ціни' ],// comments: [],// extractedComments: [],// flags: {},// obsolete: false,// nplurals: 3 },// ...// ]
LIMIT/OFFSET
table; // offset 10 limit 20
UPDATE
table// msgid ""// msgstr ""// "Content-Type: text/plain; charset=utf-8\n"// "Plural-Forms: nplurals=2; plural=(n!=1);\n" // #: tests/fixtures/checkTest/check-trans-exist.js:2// #: tests/fixtures/checkTest/check-trans-exist.js:3// msgid "test"// msgstr "" table; // 1table; // msgid ""// msgstr ""// "Content-Type: text/plain; charset=utf-8\n"// "Plural-Forms: nplurals=2; plural=(n!=1);\n" // #: tests/fixtures/checkTest/check-trans-exist.js:2// #: tests/fixtures/checkTest/check-trans-exist.js:3// msgid "test"// msgstr "value"
Or as db
// sync to filedb;
Plurals
In case message has multiple plural forms, all operations must be made by specifying an additional index in the column name i.e:
msgstr2
As indexes start with 0, this refers to third form of the message, otherwise it will be treated like singular.
// get all items with second form equals to 'xxx'table // update an item and set it's first form to 'yyy'table
Plans
- IN operator
- ORDER operator
- handy functions(LOWER, UPPER)
Kudos
rubenv for excelent pofile library.
godmodelabs for handy flora-sql-parser