diff --git a/packages/nx-phrase/package.json b/packages/nx-phrase/package.json index 5e9ea0a..89ab054 100644 --- a/packages/nx-phrase/package.json +++ b/packages/nx-phrase/package.json @@ -1,6 +1,6 @@ { "name": "@porscheofficial/nx-phrase", - "version": "0.2.1", + "version": "0.3.0", "repository": { "type": "url", "url": "https://github.com/porscheofficial/nx-plugins", diff --git a/packages/nx-phrase/src/executors/build/schema.json b/packages/nx-phrase/src/executors/build/schema.json index 3ed9dfb..6b36242 100644 --- a/packages/nx-phrase/src/executors/build/schema.json +++ b/packages/nx-phrase/src/executors/build/schema.json @@ -71,6 +71,16 @@ "useFallbackLocale": { "description": "(optional) Pass fallback_locale during locale download to api. All translations that don't exist in the locale currently being downloaded will be complemented with the ones from the fallback_locale", "type": "boolean" + }, + "formatOptions": { + "description": "Options for the various file formats", + "type": "object", + "properties": { + "escapeSingleQuotes": { + "description": "Escape single quotes in L10N strings (optional, default is true). This option is only relevant for fileFormat 'properties'.", + "type": "boolean" + } + } } }, "required": ["projectId", "uploadLanguageId"] diff --git a/packages/nx-phrase/src/executors/pull/schema.json b/packages/nx-phrase/src/executors/pull/schema.json index 700e70d..9ed5f21 100644 --- a/packages/nx-phrase/src/executors/pull/schema.json +++ b/packages/nx-phrase/src/executors/pull/schema.json @@ -34,6 +34,16 @@ "useFallbackLocale": { "description": "Pass fallback_locale during locale download to api. All translations that don't exist in the locale currently being downloaded will be complemented with the ones from the fallback_locale", "type": "boolean" + }, + "formatOptions": { + "description": "Options for the various file formats", + "type": "object", + "properties": { + "escapeSingleQuotes": { + "description": "Escape single quotes in L10N strings (optional, default is true). This option is only relevant for fileFormat 'properties'.", + "type": "boolean" + } + } } }, "required": ["projectId", "output"] diff --git a/packages/nx-phrase/src/lib/config.ts b/packages/nx-phrase/src/lib/config.ts index c1189a1..df248e3 100644 --- a/packages/nx-phrase/src/lib/config.ts +++ b/packages/nx-phrase/src/lib/config.ts @@ -1,7 +1,7 @@ import { existsSync, readFileSync } from "fs-extra" import { resolve } from "path" -import { NonSensitiveArgs } from "./types" +import { FormatOptions, NonSensitiveArgs } from "./types" import { ExecutorContext } from "@nx/devkit" import { load } from "js-yaml" import { PhraseClientConfig } from "./phrase" @@ -75,6 +75,10 @@ function validateConfig(config: NonSensitiveArgs, projectName: string, requiredC return !error } +export const defaultFormatOptions: FormatOptions = { + escapeSingleQuotes: true, +} + export function getConfig( options: BuildExecutorSchema, context: ExecutorContext, @@ -112,6 +116,12 @@ export function getConfig( phraseKeyFilter: options.phraseKeyFilter, useFallbackLocale: options.useFallbackLocale, useSourceLocaleAsFallback: options.useSourceLocaleAsFallback, + formatOptions: options.formatOptions + ? { + escapeSingleQuotes: + options.formatOptions.escapeSingleQuotes ?? defaultFormatOptions.escapeSingleQuotes, + } + : { ...defaultFormatOptions }, } as NonSensitiveArgs if (!validateConfig(config, projectName, requiredConfigurationProperties)) { diff --git a/packages/nx-phrase/src/lib/phrase.ts b/packages/nx-phrase/src/lib/phrase.ts index 4f3ba3f..5e4d1de 100644 --- a/packages/nx-phrase/src/lib/phrase.ts +++ b/packages/nx-phrase/src/lib/phrase.ts @@ -118,7 +118,7 @@ export class PhraseClient { const url = new URL(`${this.#baseUrl}/projects/${projectId}/locales/${id}/download`) for (const argName in otherArgs) { - if (otherArgs[argName]) { + if (otherArgs[argName] !== undefined) { url.searchParams.set(argName, otherArgs[argName]) } } diff --git a/packages/nx-phrase/src/lib/pull.ts b/packages/nx-phrase/src/lib/pull.ts index c18c98b..5732e10 100644 --- a/packages/nx-phrase/src/lib/pull.ts +++ b/packages/nx-phrase/src/lib/pull.ts @@ -21,6 +21,11 @@ export class PullHelper { async downloadTranslations(locales: PhraseLocale[]): Promise { const phrase = new PhraseClient(this.config.phraseClientConfig) + const formatOptions = { + "format_options[escape_single_quotes]": + this.config.fileFormat === "properties" ? this.config.formatOptions.escapeSingleQuotes : undefined, + } + const translations: Record = {} for (const locale of locales) { const { id, name } = locale @@ -31,12 +36,13 @@ export class PullHelper { branch: this.config.branch, file_format: this.config.fileFormat, // Use phrase API fallback locale? - ...(this.config.useFallbackLocale + ...(this.config.useFallbackLocale && locale.fallback_locale ? { fallback_locale_id: locale.fallback_locale.id, include_empty_translations: true, } : {}), + ...formatOptions, }) translations[name] = localeData diff --git a/packages/nx-phrase/src/lib/types.d.ts b/packages/nx-phrase/src/lib/types.d.ts index 4f29040..209489e 100644 --- a/packages/nx-phrase/src/lib/types.d.ts +++ b/packages/nx-phrase/src/lib/types.d.ts @@ -1,3 +1,7 @@ +export interface FormatOptions { + escapeSingleQuotes: boolean +} + export interface NonSensitiveArgs { projectId: string branch: string @@ -15,4 +19,5 @@ export interface NonSensitiveArgs { useFallbackLocale: boolean inputFile: string workingDirectory: string + formatOptions: FormatOptions }