Skip to content

Commit

Permalink
feat: create target xlf file if it does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
kyubisation committed Sep 27, 2020
1 parent 663abb4 commit a0fa5c5
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions builders/t9n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,22 @@ export async function t9n(options: Options, context: BuilderContext): Promise<Bu
Object.keys(locales).map(async (language) => {
const locale = locales[language];
const targetPath = join(workspaceRoot, locale.translation);
const result = await serializationStrategy.deserializeTarget(targetPath);
const target = targetRegistry.register(result.language, result.unitMap, locale.baseHref);
if (host.isFile(targetPath)) {
const result = await serializationStrategy.deserializeTarget(targetPath);
const target = targetRegistry.register(result.language, result.unitMap, locale.baseHref);

const normalizedPath = targetPathBuilder.createPath(target);
if (targetPath !== normalizedPath) {
context.logger.info(
`Normalizing path for ${target.language}\n => Moving ${relative(
workspaceRoot,
targetPath
)} to ${relative(workspaceRoot, normalizedPath)}`
);
await nodeHost.rename(targetPath, normalizedPath).toPromise();
const normalizedPath = targetPathBuilder.createPath(target);
if (targetPath !== normalizedPath) {
context.logger.info(
`Normalizing path for ${target.language}\n => Moving ${relative(
workspaceRoot,
targetPath
)} to ${relative(workspaceRoot, normalizedPath)}`
);
await nodeHost.rename(targetPath, normalizedPath).toPromise();
}
} else {
await targetRegistry.create(language, locale.baseHref);
}
})
);
Expand Down

0 comments on commit a0fa5c5

Please sign in to comment.