19 Commits

Author SHA1 Message Date
Ruben Vermeersch
e2bdad57be Release v1.1.3 2022-01-19 15:37:38 +01:00
Ruben Vermeersch
2e7e5b6be8 Merge pull request #44 from iddan-flycode/patch-1
Make obsolete public
2022-01-19 15:37:10 +01:00
Iddan Aaronsohn
61363b872b Make obsolete public
Currently, it is impossible in TypeScript to tell if an item is obsolete or not.
2022-01-19 16:14:10 +02:00
Ruben Vermeersch
8d2b93c6c7 Fix build 2021-12-01 10:11:17 +01:00
dependabot[bot]
acb555b562 Bump grunt from 1.0.4 to 1.3.0
Bumps [grunt](https://github.com/gruntjs/grunt) from 1.0.4 to 1.3.0.
- [Release notes](https://github.com/gruntjs/grunt/releases)
- [Changelog](https://github.com/gruntjs/grunt/blob/main/CHANGELOG)
- [Commits](https://github.com/gruntjs/grunt/compare/v1.0.4...v1.3.0)

---
updated-dependencies:
- dependency-name: grunt
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-01 09:08:09 +00:00
Ruben Vermeersch
88364bc5e1 Release v1.1.2 2021-12-01 10:06:48 +01:00
Remko Tronçon
685be92923 Support multiple spaces after msgid 2021-12-01 09:48:44 +01:00
Ruben Vermeersch
ff1b888af1 Release v1.1.1 2021-03-09 09:22:33 +01:00
Ruben Vermeersch
3535e60695 Rebuild 2021-03-09 09:22:03 +01:00
Ruben Vermeersch
11b1affe5b Merge pull request #40 from septs/master
lazy require fs
2021-03-09 09:21:07 +01:00
Septs
29d40186c9 lazy require fs 2021-03-06 01:59:15 +08:00
Ruben Vermeersch
d6937a7da2 Merge pull request #39 from rubenv/revert-38-patch-1
Revert "Fix type of PO.Item"
2020-04-21 09:38:15 +02:00
Ruben Vermeersch
c62b82a98d Revert "Fix type of PO.Item" 2020-04-21 09:38:00 +02:00
Ruben Vermeersch
fe23027f32 Merge pull request #38 from kirillku/patch-1
Fix type of PO.Item
2020-04-21 09:37:31 +02:00
Kirill Kubryakov
d92e1f9e89 Fix type of PO.Item 2020-04-21 10:25:53 +03:00
Ruben Vermeersch
0359aa12a4 Release v1.1.0 2019-06-25 13:31:56 +02:00
Ruben Vermeersch
6357bf3edd Merge pull request #34 from septs/master
rewrite typescript definition file
2019-06-25 13:31:05 +02:00
Septs
3b28b3ed08 remove test code 2019-06-25 19:27:45 +08:00
Septs
207308a1ac rewrite ts define 2019-06-25 19:12:53 +08:00
10 changed files with 5931 additions and 58 deletions

View File

@@ -53,7 +53,7 @@ module.exports = (grunt) ->
bump:
options:
files: ['package.json', 'bower.json']
files: ['package.json', 'package-lock.json', 'bower.json']
commitFiles: ['-a']
pushTo: 'origin'

View File

@@ -1,6 +1,6 @@
{
"name": "pofile",
"version": "1.0.11",
"version": "1.1.3",
"authors": [
"Ruben Vermeersch <ruben@rocketeer.be>"
],

10
dist/pofile.js vendored
View File

@@ -1,8 +1,6 @@
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
require=(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
},{}],"pofile":[function(require,module,exports){
var fs = require('fs');
function trim(string) {
return string.replace(/^\s+|\s+$/g, '');
}
@@ -16,7 +14,7 @@ var PO = function () {
};
PO.prototype.save = function (filename, callback) {
fs.writeFile(filename, this.toString(), callback);
require('fs').writeFile(filename, this.toString(), callback);
};
PO.prototype.toString = function () {
@@ -68,7 +66,7 @@ PO.prototype.toString = function () {
};
PO.load = function (filename, callback) {
fs.readFile(filename, 'utf-8', function (err, data) {
require('fs').readFile(filename, 'utf-8', function (err, data) {
if (err) {
return callback(err);
}
@@ -85,7 +83,7 @@ PO.parse = function (data) {
var headers = [];
//everything until the first 'msgid ""' is considered header
while (sections[0] && (headers.length === 0 || headers[headers.length - 1].indexOf('msgid ""') < 0)) {
if (sections[0].match(/msgid "[^"]/)) {
if (sections[0].match(/msgid\s+"[^"]/)) {
//found first real string, adding a dummy header item
headers.push('msgid ""');
} else {

2
dist/pofile.min.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,3 @@
var fs = require('fs');
function trim(string) {
return string.replace(/^\s+|\s+$/g, '');
}
@@ -13,7 +11,7 @@ var PO = function () {
};
PO.prototype.save = function (filename, callback) {
fs.writeFile(filename, this.toString(), callback);
require('fs').writeFile(filename, this.toString(), callback);
};
PO.prototype.toString = function () {
@@ -65,7 +63,7 @@ PO.prototype.toString = function () {
};
PO.load = function (filename, callback) {
fs.readFile(filename, 'utf-8', function (err, data) {
require('fs').readFile(filename, 'utf-8', function (err, data) {
if (err) {
return callback(err);
}
@@ -82,7 +80,7 @@ PO.parse = function (data) {
var headers = [];
//everything until the first 'msgid ""' is considered header
while (sections[0] && (headers.length === 0 || headers[headers.length - 1].indexOf('msgid ""') < 0)) {
if (sections[0].match(/msgid "[^"]/)) {
if (sections[0].match(/msgid\s+"[^"]/)) {
//found first real string, adding a dummy header item
headers.push('msgid ""');
} else {

5847
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
{
"name": "pofile",
"description": "Parse and serialize Gettext PO files.",
"version": "1.0.11",
"version": "1.1.3",
"author": {
"name": "Ruben Vermeersch",
"email": "ruben@savanne.be",
@@ -37,7 +37,8 @@
},
"devDependencies": {
"browserify": "~14.0.0",
"grunt": "~1.0.1",
"coffeescript": "^2.6.1",
"grunt": "~1.3.0",
"grunt-browserify": "~5.0.0",
"grunt-bump": "0.8.0",
"grunt-contrib-clean": "~1.0.0",

85
pofile.d.ts vendored
View File

@@ -1,44 +1,45 @@
declare module pofile {
function parse(data: string): PO;
function load(fileName: string, callback: (err: NodeJS.ErrnoException | null, po: PO) => void): void;
class PO {
public comments: string[];
public extractedComments: string[];
public items: Item[];
public headers: Partial<IHeaders>
public save(filename: string, callback: (err?: NodeJS.ErrnoException) => void): void;
public toString(): string;
}
interface IHeaders {
'Project-Id-Version': string;
'Report-Msgid-Bugs-To': string;
'POT-Creation-Date': string;
'PO-Revision-Date': string;
'Last-Translator': string;
'Language': string;
'Language-Team': string;
'Content-Type': string;
'Content-Transfer-Encoding': string;
'Plural-Forms': string;
}
class Item {
public msgid: string;
public msgctxt?: string;
public references: string[];
public msgid_plural?: string;
public msgstr: string[];
public comments: string[];
public extractedComments: string[];
public flags: { [flag: string]: boolean | undefined }
private nplurals: number;
private obsolete: boolean;
public toString(): string;
}
declare interface IHeaders {
'Project-Id-Version': string;
'Report-Msgid-Bugs-To': string;
'POT-Creation-Date': string;
'PO-Revision-Date': string;
'Last-Translator': string;
'Language': string;
'Language-Team': string;
'Content-Type': string;
'Content-Transfer-Encoding': string;
'Plural-Forms': string;
[name: string]: string;
}
export = pofile
declare class Item {
public msgid: string;
public msgctxt?: string;
public references: string[];
public msgid_plural?: string;
public msgstr: string[];
public comments: string[];
public extractedComments: string[];
public flags: Record<string, boolean | undefined>;
public obsolete: boolean;
private nplurals: number;
public toString(): string;
}
declare class PO {
public comments: string[];
public extractedComments: string[];
public items: Item[];
public headers: Partial<IHeaders>
public static parse(data: string): PO;
public static parsePluralForms(forms: string): PO;
public static load(fileName: string, callback: (err: NodeJS.ErrnoException, po: PO) => void): void;
public static Item: typeof Item;
public save(fileName: string, callback: (err: NodeJS.ErrnoException) => void): void;
public toString(): string;
}
export = PO

View File

@@ -0,0 +1,8 @@
# some comment
msgid "First id, no header"
msgstr ""
msgid "A second string"
msgstr ""

View File

@@ -70,4 +70,24 @@ describe('PO files with no headers', function () {
assert.equal(po.items.length, 2);
});
});
describe('advanced example with extra spaces', function () {
var po;
before(function (done) {
PO.load(__dirname + '/fixtures/no_header_extra_spaces.po', function (err, result) {
assert.equal(err, null);
po = result;
done();
});
});
it('Parses the po file', function () {
assert.notEqual(po, null);
});
it('Finds all items', function () {
assert.equal(po.items.length, 2);
});
});
});