Skip to content

Commit

Permalink
feat: default tags for new keys (#3339)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 authored May 30, 2024
1 parent 7ea64c1 commit 7d2cac8
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 18 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/Controller/Plugins/Plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export function Plugins(
addPlugin,
findPositions: findPositions,
run() {
const { apiKey, apiUrl, projectId, observerOptions } =
const { apiKey, apiUrl, projectId, observerOptions, tagNewKeys } =
getInitialOptions();
instances.ui = plugins.ui?.({
apiKey: apiKey!,
Expand All @@ -197,6 +197,7 @@ export function Plugins(
changeTranslation,
findPositions,
onPermanentChange: (data) => events.onPermanentChange.emit(data),
tagNewKeys,
});

instances.observer?.run({
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/Controller/State/initState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ export type TolgeeOptionsInternal = {
* Define custom fetch function, used for fetching the translations
*/
fetch: FetchFn;

/**
* Specify tags that will be preselected for non-existant keys.
*/
tagNewKeys?: string[];
};

export type TolgeeOptions = Partial<
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export type UiProps = {
findPositions: (key?: string | undefined, ns?: NsFallback) => KeyPosition[];
changeTranslation: ChangeTranslationInterface;
onPermanentChange: (props: TranslationDescriptor) => void;
tagNewKeys?: string[];
};

export type UiKeyOption = {
Expand Down
3 changes: 3 additions & 0 deletions packages/web/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export const App = () => {
<div style={{ pointerEvents: 'none' }}>
<div>{tolgee.t('app-title')}</div>
</div>
<div>
<div>{tolgee.t('new-key')}</div>
</div>
</StyledContainer>
);
};
1 change: 1 addition & 0 deletions packages/web/src/app/basicTolgee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const tolgee = Tolgee()
...secrets,
availableLanguages: ['en', 'cs', 'fr', 'de'],
defaultLanguage: 'en',
tagNewKeys: ['draft'],
});

export const useTolgee = (events?: TolgeeEvent[]): TolgeeInstance => {
Expand Down
6 changes: 5 additions & 1 deletion packages/web/src/package/ui/KeyDialog/dialogContext/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ export const [DialogProvider, useDialogActions, useDialogContext] =
setPluralArgName(firstKey?.keyPluralArgName);
}
_setTranslationsForm(result);
setTags(firstKey?.keyTags?.map((t) => t.name) || []);
if (firstKey) {
setTags(firstKey?.keyTags?.map((t) => t.name) || []);
} else {
setTags(props.uiProps.tagNewKeys ?? []);
}
setScreenshots(
firstKey?.screenshots?.map((sc) => ({
...sc,
Expand Down
18 changes: 3 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testapps/next-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@tolgee/react": "5.26.0",
"@tolgee/web": "5.26.0",
"next": "14.1.4",
"next-intl": "^3.2.3",
"next-intl": "3.2.3",
"react": "18.2.0",
"react-dom": "18.2.0"
},
Expand Down

0 comments on commit 7d2cac8

Please sign in to comment.