Skip to content

Commit 55cffc1

Browse files
authored
Merge pull request #39 from PolymerLabs/transform
Implement transform output mode
2 parents d92d73b + 12497bf commit 55cffc1

File tree

9 files changed

+596
-60
lines changed

9 files changed

+596
-60
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## Unreleased
99

1010
- [BREAKING] The `tsOut` parameter is replaced by the new `output` object with
11-
`mode: "runtime"`. Other outputs modes will follow.
11+
`mode: "runtime"|"transform"`.
12+
13+
- Add `transform` output mode, which emits an entire copy of the program in each
14+
locale, where all `msg` calls have been replaced with the raw translated
15+
template for that locale.
1216

1317
- Add ability to generate a `setLocale` function by setting
1418
`output.exportSetLocaleFunction: true`.

src/outputters/runtime.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {applyPatches, Patches} from '../patches';
1414
import {Locale} from '../locales';
1515
import {Config} from '../config';
1616
import {KnownError} from '../error';
17+
import {escapeStringToEmbedInTemplateLiteral} from '../typescript';
1718
import * as fs from 'fs';
1819
import * as pathLib from 'path';
1920

@@ -443,7 +444,7 @@ function makeMessageString(
443444
const fragments = [];
444445
for (const content of contents) {
445446
if (typeof content === 'string') {
446-
fragments.push(escapeStringLiteral(content));
447+
fragments.push(escapeStringToEmbedInTemplateLiteral(content));
447448
} else {
448449
fragments.push(content.untranslatable);
449450
}
@@ -460,14 +461,3 @@ function makeMessageString(
460461
return msgStr;
461462
}
462463
}
463-
464-
/**
465-
* Escape a string such that it can be safely embedded in a JavaScript template
466-
* literal (backtick string).
467-
*/
468-
function escapeStringLiteral(unescaped: string): string {
469-
return unescaped
470-
.replace(`\\`, `\\\\`)
471-
.replace('`', '\\`')
472-
.replace('$', '\\$');
473-
}

0 commit comments

Comments
 (0)