Commit Graph

47 Commits

Author SHA1 Message Date
4aa2cbfe04 cleanup
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2022-04-24 12:31:26 +03:00
Remko Tronçon
685be92923 Support multiple spaces after msgid 2021-12-01 09:48:44 +01:00
Septs
29d40186c9
lazy require fs 2021-03-06 01:59:15 +08:00
Martin Bachtík
8bd7810703 header order 2018-05-25 11:21:23 +02:00
Taavi Sangel
579a5635a6
added support for multiline msgctxt strings 2017-11-21 13:29:28 +02:00
janhommes
a6937bb7f0 Fixed issue with plural multiline text. 2017-09-14 14:37:45 +02:00
Andréas Livet
0fcff887fe Avoid putting a space in empty comments
In our pipeline, empty comments in po files are generated without
a space after '#' and saving a po file using pofile lib generates
unwanted diff that need to be handle manually which is really annoying.
This pull request simply trim the comment line.
2017-03-17 14:25:20 +01:00
rosston
0e3a6d74f3 Stub out missing translations according to language plurals. 2017-03-08 10:24:51 -05:00
rosston
115459160e Use msgstr[0] when stringifying an untranslated plural item. 2017-02-10 10:18:01 -05:00
rosston
79407fcf5e Remove lodash.isarray (use native Array.isArray).
Other code was already depending on Object.keys() and
Array.prototype.filter(), which are also ES5 along with
Array.isArray().
2017-02-09 22:44:46 -05:00
Julian Bäume
71bb04f046 add support for po files without headers
basically fix all the examples.
2015-09-22 23:36:12 +02:00
Julian Bäume
d1be0f51b0 fix issue #16
add a blank line in the comments of the headers of the big.po file. This
breaks parsing the headers. msgcat of gettext tools just ignores empty
lines until a header is found and treats everything above as header
comment.

The change to the library itself fixes the tests again, after the blank
linke broke 3.
2015-09-21 09:13:43 +02:00
Ruben Vermeersch
b9394176b1 Handle extracted comments in headers 2015-08-20 15:12:56 +02:00
Ruben Vermeersch
104d114d5d Only write flags when they evaluate to true. 2015-07-17 10:35:25 +02:00
Julian Bäume
e1742e66a6 properly escape all unprintable characters
writing messages should no be in line with gettext tools. I tested
using msgcat, it provides the same results.

For some common use-cases I wrote explicit tests, for uncommon and
even unwanted use-cases I wrote one test to make sure pofile works
like msgcat for those messages
2014-06-23 18:24:02 +02:00
Candid Dauth
4cfebdee80 Fixed unescaping of all escaped C String characters.
Signed-off-by: Julian Bäume <julian@svg4all.de>

Conflicts:
	lib/po.js
2014-06-23 15:03:58 +02:00
Julian Bäume
d8fc514359 don't remove \n characters from written po file
in Item.toString, all \n characters are removed from the output.
The gettext tools however leave those characters intact. This
will now produce the same output as tools like msgcat.
2014-06-23 15:03:58 +02:00
Julian Bäume
af94d8ff5e restore previous behaviour with \n in strings
An incompatible change (that actually breaks po parsing after writing) had
been introduced with commit e164fcfe9d. If
_process returned an array (which is the case for strings containing \n
character), array.toString will return a comma separated list, which is not
valid po syntax. Added a test to restore the behaviour from before the
e164fcfe9d.
2014-06-23 12:30:04 +02:00
Julian Bäume
08e7db58b3 handle empty comments correctly
since the lines in the parser have all newline characters removed, \s+ will
not match empty comments.

Added an example that makes other tests fail without this patch.
2014-06-19 17:04:03 +02:00
Ruben Vermeersch
656bfd0b8d Add JSCS, fix style. 2014-06-19 14:16:30 +02:00
Julian Bäume
e164fcfe9d new implementation of items marked obsolete
the current implementation of items marked obsolete did not allow "plain"
comments for these items. However, this is perfectly fine according to
the original gettext tools. When writing a po file, comments for obsolete
items don't contain the '#~ ' mark (tested using msgcat), so this is now
also aligned with the behaviour of the original gettext tools.

For all these cases I added examples in the po files, that failed with the
current implementation and work fine after these changes.
2014-06-19 13:47:30 +02:00
Julian Bäume
73b267b3e8 add support for multiline string in headers
Some languages (such as Polish, Russian or Romanian) do have more
complicated plural forms. Those are still expressible by a more
complicated mathematical expression. However, the msgmerge tool of
gettext will in these cases write multiline header fields. When parsing
such files with this lib, the headers get screwed up, so this patch
provides an example (from a pl_PL po file) and fixes this by joining the
lines in the header, before doing the actual parsing.
2014-03-21 10:54:32 +01:00
Ruben Vermeersch
dba7465ba7 Remove unneeded if-clauses. 2014-03-07 10:17:52 +01:00
Ruben Vermeersch
d426c114c7 Add support for obsolete items to fix broken parsing. 2014-03-07 10:15:50 +01:00
Julian Bäume
94f5f4a83e add reverse method of extract(string)
during PO.parse, an extract(string) method is called on each string to
unescape some characters (like " and \). This process should be reverted
in the toString method.

The PO spec says, that all strings should be C-Strings. Otherwise tools
like msgmerge (from the gettext package) will fail parsing po files written
by this library.
2014-03-05 10:13:30 +01:00
Gabe Gorelick
ac85ba0b9c Handle extracted comments 2014-03-02 13:17:20 -05:00
Gabe Gorelick
ada76116b0 Include comments in PO.Item output
Fixes #5
2014-03-02 12:41:40 -05:00
Julian Bäume
a5f3059661 fix default value of msgctxt field
I added a few more edge-cases to the tests for the new msgctxt field and
revealed a bug during that. The default value has been set to empty
string, but should have been null, since the spec says, this field is
optional.
2014-01-22 14:14:03 +01:00
Julian Bäume
c046b62873 implement writing msgctxt field
since the parser can extract this information, now, the writer should
also be able to write it back to a po file
2014-01-21 15:06:11 +01:00
Julian Bäume
6790bfb466 add parsing support for msgctxt field of poitems
The gettext format specifies a msgctxt field for translated items. An
example of how to use this field has been added to the tests and the
parsing of this attribute has been implemented.
2014-01-21 15:05:58 +01:00
Ruben Vermeersch
6b2cb2e71e Stop using util.format.
This will massively shrink the browserified footprint.
2013-12-18 16:46:09 +01:00
Ruben Vermeersch
0d4f80e7f6 Write flags out when serializing. 2013-12-17 16:35:40 +01:00
Ruben Vermeersch
fff8349e25 Parse item flags. 2013-12-17 15:04:44 +01:00
Ruben Vermeersch
fe2e17990a Fix the async calls.
This is a breaking change. But that's okay, the previous behavior for
async was just plain wrong and would crash the entire node process,
which is unacceptable. A major version bump will be needed to release
this.
2013-12-17 14:30:07 +01:00
Ruben Vermeersch
e61e535a79 Add JSHint. Fix style and some potential bugs. 2013-12-16 16:36:32 +01:00
Mike Holly
f7d70f302b Merge pull request #5 from elewinso/master
added support for CRLF files - window style
2013-10-31 07:02:48 -07:00
Sander Houttekier
c7c62caa54 Update parsing of headers
Remove wrong `.replace()` statement which breaks any language file from a language ending with the character `n`. It is unclear to me why this replace is even there. As it is even invalid to replace without supplying a string with what it needs to be replaced.
2013-10-31 14:13:25 +01:00
elewinso
47adb2be9e added support for CRLF files - window style 2013-09-12 14:01:37 +03:00
Mike Holly
3eab1ece05 Fixed msgid_plural error 2012-01-15 11:31:07 -08:00
Mike Holly
899c948784 Fixed export bug. 2012-01-02 16:06:32 -08:00
Mike Holly
69fcd1b40d Made parser much more robust. Now handles files without whitespace seps. 2012-01-02 15:52:05 -08:00
Mike Holly
1e13e78654 Fixed parsing error. 2012-01-01 17:52:51 -08:00
Mike Holly
ea1fcd870f Added toString method for PO 2012-01-01 17:02:19 -08:00
Mike Holly
1bae2deab0 Fixed error in loading. 2011-12-26 18:22:05 -08:00
Mike Holly
f507223705 Added Item.toString() and moved save logic there. 2011-12-22 16:17:04 -08:00
Mike Holly
79b8009b2a Can now read and write most PO files. Added simple test. 2011-12-22 16:12:01 -08:00
Mike Holly
5ea3f06a8c Initial commit 2011-12-21 22:50:01 -08:00