Skip to content

Commit

Permalink
fix(gui): load server strings into correct namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Mar 5, 2023
1 parent eed1aeb commit ee3b278
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 9 additions & 3 deletions gui/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ export interface ApiClient {
/**
* Load extra strings from the server.
*/
strings(): Promise<Record<string, unknown>>;
strings(): Promise<Record<string, {
translation: Record<string, string>;
}>>;

/**
* Start a txt2img pipeline.
Expand Down Expand Up @@ -394,10 +396,14 @@ export function makeClient(root: string, f = fetch): ApiClient {
const res = await f(path);
return await res.json() as Array<string>;
},
async strings(): Promise<Record<string, unknown>> {
async strings(): Promise<Record<string, {
translation: Record<string, string>;
}>> {
const path = makeApiUrl(root, 'settings', 'strings');
const res = await f(path);
return await res.json() as Record<string, unknown>;
return await res.json() as Record<string, {
translation: Record<string, string>;
}>;
},
async img2img(model: ModelParams, params: Img2ImgParams, upscale?: UpscaleParams): Promise<ImageResponse> {
const url = makeImageURL(root, 'img2img', params);
Expand Down
7 changes: 5 additions & 2 deletions gui/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ export async function main() {
});

const strings = await client.strings();
for (const [lang, data] of Object.entries(strings)) {
i18n.addResourceBundle(lang, 'translation', data, true);
for (const [lang, translation] of Object.entries(strings)) {
console.log('adding strings', lang, translation);
for (const [namespace, data] of Object.entries(translation)) {
i18n.addResourceBundle(lang, namespace, data, true);
}
}

// prep zustand with a slice for each tab, using local storage
Expand Down

0 comments on commit ee3b278

Please sign in to comment.