Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Jan 19, 2025
1 parent ccf83f1 commit 67c84a0
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions packages/cli/src/parsers/formats/android-xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Parser } from "../core/types.ts";

export function createAndroidXmlParser(): Parser {
return createFormatParser({
async parse(input: string): Promise<Record<string, string>> {
async parse(input: string) {
try {
if (!input.trim().startsWith("<")) {
throw new Error("Translation file must contain valid Android XML");
Expand All @@ -28,7 +28,7 @@ export function createAndroidXmlParser(): Parser {
const strings = parsed.resources?.string || [];

for (const string of strings) {
if (string.$ && string.$.name && string._) {
if (string.$?.name && string._) {
result[string.$.name] = string._;
}
}
Expand All @@ -41,7 +41,7 @@ export function createAndroidXmlParser(): Parser {
}
},

async serialize(data: Record<string, string>): Promise<string> {
async serialize(_, data) {
try {
const resources = {
resources: {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/parsers/formats/arb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Parser } from "../core/types.ts";

export function createArbParser(): Parser {
return createFormatParser({
async parse(input: string): Promise<Record<string, string>> {
async parse(input: string) {
try {
const parsed = JSON.parse(input);
return pickBy((_, key) => !key.startsWith("@"), parsed);
Expand All @@ -15,7 +15,7 @@ export function createArbParser(): Parser {
}
},

async serialize(locale, data): Promise<string> {
async serialize(locale, data) {
try {
const result = merge({ "@@locale": locale }, data);
return JSON.stringify(result, null, 2);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/parsers/formats/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function createCsvParser(): Parser {
};

return createFormatParser({
async parse(input: string): Promise<Record<string, string>> {
async parse(input: string) {
try {
const parsed = parse(input, {
columns: true,
Expand Down Expand Up @@ -71,7 +71,7 @@ export function createCsvParser(): Parser {
}
},

async serialize(_, data, originalData): Promise<string> {
async serialize(_, data, originalData) {
const usedColumns = Array.from(
new Set([
"id",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/parsers/formats/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function createHtmlParser(): Parser {
}

return createFormatParser({
async parse(input: string): Promise<Record<string, string>> {
async parse(input: string) {
const translations: Record<string, string> = {};
const dom = new JSDOM(input);
const doc = dom.window.document;
Expand All @@ -117,7 +117,7 @@ export function createHtmlParser(): Parser {
return translations;
},

async serialize(_, translations): Promise<string> {
async serialize(_, translations) {
const dom = new JSDOM(
"<!DOCTYPE html><html><head></head><body></body></html>",
);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/parsers/formats/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Parser } from "../core/types.ts";

export function createJavaScriptParser(): Parser {
return createFormatParser({
async parse(input: string): Promise<Record<string, string>> {
async parse(input: string) {
try {
const cleanInput = preprocessInput(input);
const parsed = evaluateJavaScript(cleanInput);
Expand All @@ -17,7 +17,7 @@ export function createJavaScriptParser(): Parser {
}
},

async serialize(_, data): Promise<string> {
async serialize(_, data) {
const nested = unflatten(data);
const formatted = formatTranslationObject(nested);
return wrapInExport(formatted);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/parsers/formats/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Parser } from "../core/types.ts";

export function createJsonParser(): Parser {
return createFormatParser({
async parse(input: string): Promise<Record<string, string>> {
async parse(input: string) {
try {
const parsed = JSON.parse(jsonrepair(input));
if (typeof parsed !== "object" || parsed === null) {
Expand All @@ -19,7 +19,7 @@ export function createJsonParser(): Parser {
}
},

async serialize(_, data): Promise<string> {
async serialize(_, data) {
return `${JSON.stringify(unflatten(data), null, 2)}\n`;
},
});
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/parsers/formats/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Parser } from "../core/types.ts";

export function createMarkdownParser(): Parser {
return createFormatParser({
async parse(input: string): Promise<Record<string, string>> {
async parse(input: string) {
try {
const tokens = marked.lexer(input);
const result: Record<string, string> = {};
Expand All @@ -31,7 +31,7 @@ export function createMarkdownParser(): Parser {
}
},

async serialize(_, data): Promise<string> {
async serialize(_, data) {
try {
// Validate input data
for (const [key, value] of Object.entries(data)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/parsers/formats/po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Parser } from "../core/types.ts";

export function createPoParser(): Parser {
return createFormatParser({
async parse(input: string): Promise<Record<string, string>> {
async parse(input: string) {
try {
const result: Record<string, string> = {};
const lines = input.split("\n");
Expand Down Expand Up @@ -40,7 +40,7 @@ export function createPoParser(): Parser {
}
},

async serialize(_, data): Promise<string> {
async serialize(_, data) {
try {
if (Object.keys(data).length === 0) {
return "";
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/parsers/formats/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Parser } from "../core/types.ts";

export function createPropertiesParser(): Parser {
return createFormatParser({
async parse(input: string): Promise<Record<string, string>> {
async parse(input: string) {
const result: Record<string, string> = {};
const lines = input.split("\n");

Expand All @@ -24,7 +24,7 @@ export function createPropertiesParser(): Parser {
return result;
},

async serialize(_, data): Promise<string> {
async serialize(_, data) {
return `${Object.entries(data)
.filter(([_, value]) => value != null)
.map(([key, value]) => `${key}=${value}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/parsers/formats/xcode-strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Parser } from "../core/types.ts";

export function createXcodeStringsParser(): Parser {
return createFormatParser({
async parse(input: string): Promise<Record<string, string>> {
async parse(input: string) {
try {
const lines = input.split("\n");
const result: Record<string, string> = {};
Expand All @@ -29,7 +29,7 @@ export function createXcodeStringsParser(): Parser {
}
},

async serialize(_, data): Promise<string> {
async serialize(_, data) {
try {
const lines = Object.entries(data).map(([key, value]) => {
const escapedValue = escapeXcodeString(value);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/parsers/formats/xcode-stringsdict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Parser } from "../core/types.ts";

export function createXcodeStringsDictParser(): Parser {
return createFormatParser({
async parse(input: string): Promise<Record<string, string>> {
async parse(input: string) {
try {
const parsed = parsePlist(input) as Record<string, unknown>;
if (typeof parsed !== "object" || parsed === null) {
Expand All @@ -26,7 +26,7 @@ export function createXcodeStringsDictParser(): Parser {
}
},

async serialize(_, data): Promise<string> {
async serialize(_, data) {
try {
// Validate that all values are strings
for (const [key, value] of Object.entries(data)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/parsers/formats/xcode-xcstrings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { XcstringsOutput, XcstringsTranslationEntity } from "./types.ts";

export function createXcodeXcstringsParser(): Parser {
return createFormatParser({
async parse(input: string): Promise<Record<string, string>> {
async parse(input: string) {
try {
const parsed = JSON.parse(input);
const result: Record<string, string> = {};
Expand Down Expand Up @@ -42,7 +42,7 @@ export function createXcodeXcstringsParser(): Parser {
}
},

async serialize(_, data): Promise<string> {
async serialize(_, data) {
try {
// Validate input data
for (const [key, value] of Object.entries(data)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/parsers/formats/xliff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface XliffData {

export function createXliffParser(): Parser {
return createFormatParser({
async parse(input: string): Promise<Record<string, string>> {
async parse(input: string) {
try {
const parsed = (await xliff.xliff2js(input)) as unknown as XliffData;
if (typeof parsed !== "object" || parsed === null) {
Expand All @@ -46,7 +46,7 @@ export function createXliffParser(): Parser {
}
},

async serialize(_, data): Promise<string> {
async serialize(_, data) {
try {
// Convert flat key-value pairs to XLIFF data structure
const resources: XliffResources = {};
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/parsers/formats/xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Parser } from "../core/types.ts";

export function createXmlParser(): Parser {
return createFormatParser({
async parse(input: string): Promise<Record<string, string>> {
async parse(input: string) {
try {
if (!input.trim().startsWith("<")) {
throw new Error("Translation file must contain valid XML");
Expand All @@ -30,7 +30,7 @@ export function createXmlParser(): Parser {
}
},

async serialize(_, data): Promise<string> {
async serialize(_, data) {
try {
const builder = new Builder({
headless: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/parsers/formats/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Parser } from "../core/types.ts";

export function createYamlParser(): Parser {
return createFormatParser({
async parse(input: string): Promise<Record<string, string>> {
async parse(input: string) {
try {
const parsed = YAML.parse(input) || {};
if (typeof parsed !== "object" || parsed === null) {
Expand All @@ -19,7 +19,7 @@ export function createYamlParser(): Parser {
}
},

async serialize(_, data): Promise<string> {
async serialize(_, data) {
return YAML.stringify(unflatten(data), {
lineWidth: -1,
});
Expand Down

0 comments on commit 67c84a0

Please sign in to comment.