-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #407 from athombv/feature/translate-with-ai
Feature/translate with ai
- Loading branch information
Showing
4 changed files
with
367 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
const colors = require('colors'); | ||
|
||
const Log = require('../../../lib/Log'); | ||
const App = require('../../../lib/App'); | ||
|
||
exports.desc = 'Translate a Homey App with OpenAI'; | ||
exports.builder = yargs => { | ||
return yargs | ||
.option('languages', { | ||
default: ['nl', 'da', 'de', 'es', 'fr', 'it', 'no', 'sv', 'pl', 'ru', 'ko'].join(','), | ||
type: 'string', | ||
description: 'Comma-seperated list of languages to translate to.', | ||
}) | ||
.option('api-key', { | ||
default: process.env.OPENAI_API_KEY, | ||
type: 'string', | ||
description: 'OpenAI API key. You can create an API Key on https://platform.openai.com/api-keys.', | ||
}) | ||
.option('model', { | ||
default: 'gpt-4o', | ||
type: 'string', | ||
description: 'OpenAI model to use.', | ||
}) | ||
.option('file', { | ||
type: 'string', | ||
description: 'Absolute path to a single file to translate, instead of automatically translating the entire folder.', | ||
}); | ||
}; | ||
exports.handler = async yargs => { | ||
try { | ||
const app = new App(yargs.path); | ||
await app.translateWithOpenAI({ | ||
languages: yargs.languages.split(',').map(lang => lang.trim()), | ||
apiKey: yargs.apiKey, | ||
model: yargs.model, | ||
file: yargs.file, | ||
}); | ||
await app.preprocess(); | ||
await app.validate({ | ||
level: yargs.level, | ||
}); | ||
|
||
Log(''); | ||
Log(colors.yellow('The app has been translated using AI, so results may vary. Please check every file manually before committing.')); | ||
|
||
process.exit(0); | ||
} catch (err) { | ||
Log.error(err); | ||
process.exit(1); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.