diff --git a/packages/conf/index.d.ts b/packages/conf/index.d.ts index f1eced4bb..fe47871e6 100644 --- a/packages/conf/index.d.ts +++ b/packages/conf/index.d.ts @@ -1,6 +1,5 @@ import type { GeneratorOptions } from "@babel/core"; -export const UNICODE_REGEX: RegExp export declare type CatalogFormat = "lingui" | "minimal" | "po" | "csv" | "po-gettext"; export type CatalogFormatOptions = { origins?: boolean; diff --git a/packages/conf/src/index.ts b/packages/conf/src/index.ts index b6787306b..4d8277986 100644 --- a/packages/conf/src/index.ts +++ b/packages/conf/src/index.ts @@ -4,9 +4,7 @@ import fs from "fs" import chalk from "chalk" import { cosmiconfigSync } from "cosmiconfig" import { multipleValidOptions, validate } from "jest-validate" -// This regex will detect if a string contains unicode chars, when they're we should interpolate them -// why? because platforms like react native doesn't parse them, just doing a JSON.parse makes them UTF-8 friendly -export const UNICODE_REGEX = /\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/g; + export type CatalogFormat = "lingui" | "minimal" | "po" | "csv" export type CatalogFormatOptions = { diff --git a/packages/macro/src/macroJs.ts b/packages/macro/src/macroJs.ts index e69786075..3c5de09d0 100644 --- a/packages/macro/src/macroJs.ts +++ b/packages/macro/src/macroJs.ts @@ -1,7 +1,6 @@ import * as R from "ramda" import * as babelTypes from "@babel/types" import { NodePath } from "@babel/traverse" -import { UNICODE_REGEX } from "@lingui/conf" import ICUMessageFormat from "./icu" import { zip, makeCounter } from "./utils" @@ -266,7 +265,9 @@ export default class MacroJs { quasis: R.map((text: babelTypes.TemplateElement) => { // Don't output tokens without text. // if it's an unicode we keep the cooked value because it's the parsed value by babel (without unicode chars) - const value = UNICODE_REGEX.test(text.value.raw) ? text.value.cooked : text.value.raw + // This regex will detect if a string contains unicode chars, when they're we should interpolate them + // why? because platforms like react native doesn't parse them, just doing a JSON.parse makes them UTF-8 friendly + const value = /\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/g.test(text.value.raw) ? text.value.cooked : text.value.raw if (value === "") return null return { diff --git a/packages/macro/src/macroJsx.ts b/packages/macro/src/macroJsx.ts index f0e3cde51..4e4fcc316 100644 --- a/packages/macro/src/macroJsx.ts +++ b/packages/macro/src/macroJsx.ts @@ -1,7 +1,6 @@ import * as R from "ramda" import * as babelTypes from "@babel/types" import { NodePath } from "@babel/traverse" -import { UNICODE_REGEX } from "@lingui/conf" import ICUMessageFormat from "./icu" import { zip, makeCounter } from "./utils" @@ -231,8 +230,10 @@ export default class MacroJSX { // Don"t output tokens without text. R.evolve({ quasis: R.map((text: babelTypes.TemplateElement) => { - // Don"t output tokens without text. - const value = UNICODE_REGEX.test(text.value.raw) ? text.value.cooked : text.value.raw + // if it's an unicode we keep the cooked value because it's the parsed value by babel (without unicode chars) + // This regex will detect if a string contains unicode chars, when they're we should interpolate them + // why? because platforms like react native doesn't parse them, just doing a JSON.parse makes them UTF-8 friendly + const value = /\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/g.test(text.value.raw) ? text.value.cooked : text.value.raw if (value === "") return null return this.tokenizeText(this.clearBackslashes(value))