Skip to content

Commit

Permalink
feat: adapt to plural backend
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 committed Feb 20, 2024
1 parent 748c062 commit e5d3c99
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/parser/getTolgeeFormat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getTolgeePlurals } from "./getTolgeePlurals";
import { TolgeeFormat } from "./types";

export const getTolgeeFormat = (
input: string,
plural: boolean
): TolgeeFormat => {
if (plural) {
return getTolgeePlurals(input || "");
} else {
return { variants: { other: input } };
}
};
9 changes: 9 additions & 0 deletions src/parser/tolgeeFormatGenerateIcu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export const tolgeeFormatGenerateIcu = (format: TolgeeFormat) => {
variants.other = "";
}

let allVariantsEmpty = true;
for (const [variant, content] of Object.entries(variants)) {
if (allVariantsEmpty && content) {
allVariantsEmpty = false;
}
try {
parse(`{${parameter}, plural, other {${content}}}`);
result.push(` ${variant} {${content}}`);
Expand All @@ -34,6 +38,11 @@ export const tolgeeFormatGenerateIcu = (format: TolgeeFormat) => {
result.push(` ${variant} {${escapeIcuVariant(content || "")}}`);
}
}

if (allVariantsEmpty) {
return "";
}

result.push("}");
return result.join("");
};
2 changes: 1 addition & 1 deletion src/tolgee-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ export { getPlaceholders } from "./parser/getPlaceholders";
export { PlaceholderPlugin } from "./parser/PlaceholderPlugin";
export { parser as tolgeeParser } from "./parser/tolgeeParser";
export { tolgeeSyntax } from "./parser/tolgeeSyntax";
export { getTolgeePlurals } from "./parser/getTolgeePlurals";
export { TolgeeHighlight } from "./parser/tolgeeHighlight";
export { htmlIsolatesPlugin } from "./parser/htmlIsolatesPlugin";
export { generatePlaceholdersStyle } from "./parser/placeholdersStyle";
export { tolgeeFormatGenerateIcu } from "./parser/tolgeeFormatGenerateIcu";
export { checkParamNameIsValid } from "./parser/checkParamNameIsValid";
export { getTolgeeFormat } from "./parser/getTolgeeFormat";
export { getPluralVariants, getVariantExample } from "./utils/pluralTools";
export { getLanguageDirection } from "./utils/getLanguageDirection";
export * from "./parser/types";

0 comments on commit e5d3c99

Please sign in to comment.