[gettext-parser] Create @types (#43325)

This commit is contained in:
Lorent Lempereur 2020-04-01 00:27:23 +02:00 committed by GitHub
parent 8029da9be3
commit 72194cc4b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 0 deletions

View File

@ -0,0 +1,21 @@
import { po, mo } from 'gettext-parser';
let parsed = po.parse("foo", "utf-8");
let compiled = po.compile(parsed, {});
parsed = po.parse(Buffer.from("bar"));
compiled = po.compile(parsed, { anyOption: false });
parsed = mo.parse(compiled, "wrong-charset");
compiled = mo.compile(parsed, { noOption: 3 });
const charset: string = parsed.charset;
const firstHeader: string = parsed.headers["firstHeader"];
const firstHeaderAsString: string = firstHeader;
const firstTranslation = parsed.translations["firstContext"]["firstTranslation"];
firstTranslation.msgctxt = firstHeaderAsString;
firstTranslation.msgid = charset;
firstTranslation.msgid_plural;
firstTranslation.msgstr;
firstTranslation.comments;

42
types/gettext-parser/index.d.ts vendored Normal file
View File

@ -0,0 +1,42 @@
// Type definitions for gettext-parser 4.0
// Project: https://github.com/smhg/gettext-parser
// Definitions by: Lorent Lempereur <https://github.com/looorent>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
export interface GetTextComment {
translator: string;
reference: string;
extracted: string;
flag: string;
previous: string;
}
export interface GetTextTranslation {
msgctxt?: string;
msgid: string;
msgid_plural?: any;
msgstr: string[];
comments?: GetTextComment;
}
export interface GetTextTranslations {
charset: string;
headers: { [headerName: string]: string };
translations: { [msgctxt: string]: { [msgId: string]: GetTextTranslation } };
}
export interface PoParser {
parse: (buffer: Buffer | string, defaultCharset?: string) => GetTextTranslations;
compile: (table: GetTextTranslations, options?: any) => Buffer;
createParseStream: (buffer: any, defaultCharset?: string) => any;
}
export interface MoParser {
parse: (buffer: Buffer | string, defaultCharset?: string) => GetTextTranslations;
compile: (table: GetTextTranslations, options?: any) => Buffer;
}
export const po: MoParser;
export const mo: MoParser;

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"gettext-parser-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }