Skip to content

Commit

Permalink
massive update to hints and add localization engine
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Mandic <[email protected]>
  • Loading branch information
vladmandic committed Feb 8, 2025
1 parent 8873b2f commit a19ec07
Show file tree
Hide file tree
Showing 21 changed files with 64,821 additions and 1,627 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# Change Log for SD.Next

## Update for 2025-02-07

## Update for 2025-02-08

- **Hints**
- added/updated 100+ ui hints!
- [hints](https://github.com/vladmandic/wiki/Hints) documentation and contribution guide
- **Localization**
- full ui localization!
english, croatian, spanish, french, italian, portuguese, chinese, japanese, korean, russian
- set in *settings -> user interface -> language*
- [localization](https://github.com/vladmandic/wiki/Locale) documentation
- **Torch**:
- for **zluda** set default to `torch==2.6.0+cu126`
- **Other**:
Expand Down
4 changes: 4 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# TODO

- Check wiki links
- Update hints wiki
- Update changelog with docs and hints

Main ToDo list can be found at [GitHub projects](https://github.com/users/vladmandic/projects)

## Pending
Expand Down
66 changes: 66 additions & 0 deletions cli/localize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env node
// script used to localize sdnext ui and hints to multiple languages using google gemini ai

const fs = require('fs');
const process = require('process');
const { GoogleGenerativeAI } = require('@google/generative-ai');

const api_key = process.env.GOOGLE_AI_API_KEY;
const model = 'gemini-2.0-flash-exp';
const prompt = `
Translate attached JSON from English to {language} using following rules: fields id and label should be preserved from original, field localized should be a translated version of field label and field hint should be translated in-place.
Every JSON entry should have id, label, localized and hint fields. Output should be pure JSON without any additional text. To better match translation, context of the text is related to Stable Diffusion and topic of Generative AI.`;
const languages = {
hr: 'Croatian',
de: 'German',
es: 'Spanish',
fr: 'French',
it: 'Italian',
pt: 'Portuguese',
zh: 'Chinese',
ja: 'Japanese',
ko: 'Korean',
ru: 'Russian',
};
const chunkLines = 100;

async function localize() {
if (!api_key || api_key.length < 10) {
console.error('localize: set GOOGLE_AI_API_KEY env variable with your API key');
process.exit();
}
const genAI = new GoogleGenerativeAI(api_key);
const instance = genAI.getGenerativeModel({ model });
const raw = fs.readFileSync('html/locale_en.json');
const json = JSON.parse(raw);
for (const locale of Object.keys(languages)) {
const lang = languages[locale];
const target = prompt.replace('{language}', lang).trim();
const output = {};
const fn = `html/locale_${locale}.json`;
for (const section of Object.keys(json)) {
const data = json[section];
output[section] = [];
for (let i = 0; i < data.length; i += chunkLines) {
let markdown;
try {
const chunk = data.slice(i, i + chunkLines);
const result = await instance.generateContent([target, JSON.stringify(chunk)]);
markdown = result.response.text();
const text = markdown.replaceAll('```', '').replace(/^.*\n/, '');
const parsed = JSON.parse(text);
output[section].push(...parsed);
console.log(`localize: locale=${locale} lang=${lang} section=${section} chunk=${chunk.length} output=${output[section].length} fn=${fn}`);
} catch (err) {
console.error('localize:', err);
console.error('localize input:', { target, section, i });
console.error('localize output:', { markdown });
}
}
const txt = JSON.stringify(output, null, 2);
fs.writeFileSync(fn, txt);
}
}
}

localize();
2 changes: 1 addition & 1 deletion cli/validate-locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

if __name__ == "__main__":
sys.argv.pop(0)
fn = sys.argv[0] if len(sys.argv) > 0 else 'locale_en.json'
fn = sys.argv[0] if len(sys.argv) > 0 else 'html/locale_en.json'
if not os.path.isfile(fn):
print(f'File not found: {fn}')
sys.exit(1)
Expand Down
Loading

0 comments on commit a19ec07

Please sign in to comment.