Skip to content

Commit 66886f4

Browse files
authored
feat: add TranslationsManager from v2 branch (#541)
1 parent f8009ae commit 66886f4

File tree

9 files changed

+573
-6
lines changed

9 files changed

+573
-6
lines changed

.changeset/afraid-meals-smash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@blinkk/root-cms': patch
3+
---
4+
5+
feat: add TranslationsManager from `v2` branch (#541)

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ out/
77
*.log
88
.env
99
.turbo/
10+
*.code-workspace

packages/root-cms/core/client.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
WriteBatch,
1010
} from 'firebase-admin/firestore';
1111
import {CMSPlugin} from './plugin.js';
12+
import {TranslationsManager} from './translations-manager.js';
1213

1314
export interface Doc<Fields = any> {
1415
/** The id of the doc, e.g. "Pages/foo-bar". */
@@ -602,6 +603,30 @@ export class RootCMSClient {
602603
return false;
603604
}
604605

606+
/**
607+
* Returns a `TranslationsManager` object for managing translations.
608+
*
609+
* To get translations:
610+
* ```
611+
* await tm.loadTranslations({
612+
* ids: ['Global/strings', 'Pages/index'],
613+
* locales: ['es'],
614+
* });
615+
* ```
616+
*
617+
* NOTE: The `TranslationsManager` is a v2 feature that will eventually
618+
* replace the v1 translations system.
619+
*/
620+
getTranslationsManager(): TranslationsManager {
621+
const cmsPluginOptions = this.cmsPlugin.getConfig();
622+
if (cmsPluginOptions.experiments?.v2TranslationsManager) {
623+
throw new Error(
624+
'`v2TranslationsManager` is not enabled. update root.config.ts and add: `{experiments: {v2TranslationsManager: true}}`'
625+
);
626+
}
627+
return new TranslationsManager(this);
628+
}
629+
605630
/**
606631
* Loads translations saved in the translations collection, optionally
607632
* filtered by tag.

packages/root-cms/core/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './client.js';
22
export * from './runtime.js';
33
export * as schema from './schema.js';
4+
export * from './translations-manager.js';

packages/root-cms/core/plugin.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,15 @@ export type CMSPluginOptions = {
162162
* Experimental config options. Note: these are subject to change at any time.
163163
*/
164164
experiments?: {
165+
/**
166+
* Enables the Root CMS AI page.
167+
*/
165168
ai?: boolean | CMSAIConfig;
169+
170+
/**
171+
* Enables the v2 `TranslationsManager`.
172+
*/
173+
v2TranslationsManager?: boolean;
166174
};
167175

168176
/**

0 commit comments

Comments
 (0)