Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/twelve-eggs-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"unplugin-saykit": patch
"babel-plugin-saykit": patch
"@saykit/format-po": patch
"@saykit/config": patch
---

Add support for importing translation files directly
2 changes: 1 addition & 1 deletion .github/labeller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

'package: unplugin':
- changed-files:
- any-glob-to-any-file: ['packages/unplugin/**']
- any-glob-to-any-file: ['packages/plugin-unplugin/**']

'package: transform-js':
- changed-files:
Expand Down
1 change: 0 additions & 1 deletion examples/carbon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"scripts": {
"check": "tsc --noEmit",
"extract": "saykit extract",
"compile": "saykit compile",
"build": "tsdown",
"dev": "wrangler dev"
},
Expand Down
10 changes: 5 additions & 5 deletions examples/carbon/saykit.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { defineConfig } from '@saykit/config';
import createPoFormatter from '@saykit/format-po';
import createJsTransformer from '@saykit/transform-js';
import po from '@saykit/format-po';
import js from '@saykit/transform-js';

export default defineConfig({
sourceLocale: 'en',
locales: ['en', 'fr'],
buckets: [
{
include: ['src/**/*.ts'],
output: 'src/locales/{locale}/messages.{extension}',
formatter: createPoFormatter(),
transformer: createJsTransformer(),
output: 'src/locales/{locale}.{extension}',
formatter: po(),
transformer: js(),
},
],
});
4 changes: 2 additions & 2 deletions examples/carbon/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Say } from 'saykit';
const say = new Say({
locales: ['en', 'fr'],
messages: {
en: await import('./locales/en/messages.json').then((m) => m.default),
fr: await import('./locales/fr/messages.json').then((m) => m.default),
en: await import('./locales/en.po').then((m) => m.default),
fr: await import('./locales/fr.po').then((m) => m.default),
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language: en\n"
"Language-Team: \n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: en\n"
"Plural-Forms: \n"
"X-Generator: saykit\n"

#: src/commands/maths.ts:17
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language: fr\n"
"Language-Team: \n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: fr\n"
"Plural-Forms: \n"
"X-Generator: saykit\n"

#: src/commands/maths.ts:17
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
import './.next/types/routes.d.ts';
import './.next/dev/types/routes.d.ts';

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
1 change: 0 additions & 1 deletion examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"scripts": {
"check": "tsc --noEmit",
"extract": "saykit extract",
"compile": "saykit compile",
"dev": "next dev",
"build": "next build",
"start": "next start"
Expand Down
12 changes: 6 additions & 6 deletions examples/nextjs/saykit.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { defineConfig } from '@saykit/config';
import createPoFormatter from '@saykit/format-po';
import createJsTransformer from '@saykit/transform-js';
import createJsxTransformer from '@saykit/transform-jsx';
import po from '@saykit/format-po';
import js from '@saykit/transform-js';
import jsx from '@saykit/transform-jsx';

export default defineConfig({
sourceLocale: 'en',
locales: ['en', 'fr'],
buckets: [
{
include: ['src/**/*.{ts,tsx}'],
output: 'src/locales/{locale}/messages.{extension}',
formatter: createPoFormatter(),
transformer: [createJsTransformer(), createJsxTransformer()],
output: 'src/locales/{locale}.{extension}',
formatter: po(),
transformer: [js(), jsx()],
},
],
});
7 changes: 3 additions & 4 deletions examples/nextjs/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'server-only';
import { unstable_createWithSay } from '@saykit/react/server';
import { Say } from 'saykit';
import en from './locales/en.po';
import fr from './locales/fr.po';

const say = new Say({
locales: ['en', 'fr'],
messages: {
en: await import('./locales/en/messages.json').then((m) => m.default),
fr: await import('./locales/fr/messages.json').then((m) => m.default),
},
messages: { en, fr },
});

export const withSay = unstable_createWithSay(say);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language: en\n"
"Language-Team: \n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: en\n"
"Plural-Forms: \n"
"X-Generator: saykit\n"

msgid "Hello from the <0>{region}</0>"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language: fr\n"
"Language-Team: \n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: fr\n"
"Plural-Forms: \n"
"X-Generator: saykit\n"

msgid "Hello from the <0>{region}</0>"
Expand Down
1 change: 0 additions & 1 deletion examples/tanstack-start/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"scripts": {
"check": "tsc --noEmit",
"extract": "saykit extract",
"compile": "saykit compile",
"build": "vite build && tsc --noEmit",
"dev": "vite dev"
},
Expand Down
12 changes: 6 additions & 6 deletions examples/tanstack-start/saykit.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { defineConfig } from '@saykit/config';
import createPoFormatter from '@saykit/format-po';
import createJsTransformer from '@saykit/transform-js';
import createJsxTransformer from '@saykit/transform-jsx';
import po from '@saykit/format-po';
import js from '@saykit/transform-js';
import jsx from '@saykit/transform-jsx';

export default defineConfig({
sourceLocale: 'en',
locales: ['en', 'fr'],
buckets: [
{
include: ['src/**/*.{ts,tsx}'],
output: 'src/locales/{locale}/messages.{extension}',
formatter: createPoFormatter(),
transformer: [createJsTransformer(), createJsxTransformer()],
output: 'src/locales/{locale}.{extension}',
formatter: po(),
transformer: [js(), jsx()],
},
],
});
4 changes: 2 additions & 2 deletions examples/tanstack-start/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Say } from 'saykit';
const say = new Say({
locales: ['en', 'fr'],
messages: {
en: await import('./locales/en/messages.json').then((m) => m.default),
fr: await import('./locales/fr/messages.json').then((m) => m.default),
en: await import('./locales/en.po').then((m) => m.default),
fr: await import('./locales/fr.po').then((m) => m.default),
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language: en\n"
"Language-Team: \n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: en\n"
"Plural-Forms: \n"
"X-Generator: saykit\n"

msgid "Count: {count}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language: fr\n"
"Language-Team: \n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: fr\n"
"Plural-Forms: \n"
"X-Generator: saykit\n"

msgid "Count: {count}"
Expand Down
24 changes: 0 additions & 24 deletions packages/config/src/commands/build.ts

This file was deleted.

21 changes: 0 additions & 21 deletions packages/config/src/commands/compile.ts

This file was deleted.

20 changes: 6 additions & 14 deletions packages/config/src/commands/extract.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
import { Command } from '@commander-js/extra-typings';
import { resolveConfig } from '~/features/loader/resolve.js';
import { resolveConfig } from '~/features/loader/index.js';
import Logger from '~/features/logger.js';
import { BucketExtractWorker } from '~/features/workers/extract-worker.js';

export default new Command('extract')
.description('Extract messages from source files')
.option('-v, --verbose', 'enable verbose logging', false)
.option('-q, --quiet', 'suppress all logging', false)
.option('-w, --watch', 'watch source files for changes', false)
.action(async (options) => {
const config = await resolveConfig('saykit');
const config = resolveConfig();
const logger = new Logger(options);
logger.header('🛠 Extracting Messages');

const tasks = config.buckets.map(async (bucket) => {
const worker = new BucketExtractWorker(config, bucket, logger);
await worker.scanAll();
await worker.writeAll();
});

const results = await Promise.allSettled(tasks);
const rejections = results.filter((r): r is PromiseRejectedResult => r.status === 'rejected');
if (rejections.length > 0) {
const errors = rejections.map((r) => r.reason).join('\n');
throw new Error(`Bucket extraction failed:\n${errors}`);
}
const workers = config.buckets.map((b) => new BucketExtractWorker(config, b, logger));
await Promise.all(workers.map((w) => w.scan().then(() => w.write())));
if (options.watch) await Promise.all(workers.map((w) => w.watch()));
});
4 changes: 0 additions & 4 deletions packages/config/src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#!/usr/bin/env node

import { program } from '@commander-js/extra-typings';
import build from './build.js';
import compile from './compile.js';
import extract from './extract.js';

program
.name('saykit')
.helpOption('-h, --help', 'Display help for command')
.helpCommand('help [command]', 'Display help for command')
.addCommand(extract)
.addCommand(compile)
.addCommand(build)
.parse();
5 changes: 5 additions & 0 deletions packages/config/src/features/catalogue/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ export function expandBucketOutputPath(
.replaceAll('{extension}', extension.slice(1));
return resolve(outputMessageTemplate);
}

export function expandBucketOutputIgnoreDirectory(bucket: Bucket) {
const [prefix] = bucket.output.split('{locale}');
return resolve(prefix || '.');
}
Loading
Loading