lokalise / i18n-ally

🌍 All in one i18n extension for VS Code
https://marketplace.visualstudio.com/items?itemName=lokalise.i18n-ally
MIT License
3.93k stars 315 forks source link

add option to choose between formal and informal on deepl translations #919

Open Dumdidum12 opened 1 year ago

Dumdidum12 commented 1 year ago

HI there :), For vsce would be fantastic to add a option (provided by the Deepl API) to select that a text (e.g. german, france, spanish ...) could be translated formally or informally. I have this built in for me locally but I can't update Ally because my changes are gone after update.

The integration would be super simple:

  1. deepl.ts -> class DeepL extends TranslateEngine -> translate: add to the data the paramenter formality with the values default (for normal translation) and prefer_less (for informally translation)

    class DeepL extends TranslateEngine {
    async translate(options: TranslateOptions) {
    try {
      const res: DeepLTranslateRes = await deepl({
        method: 'POST',
        url: '/translate',
        data: {
          text: options.text,
          source_lang: stripeLocaleCode(options.from || undefined),
          target_lang: stripeLocaleCode(options.to),
          formality: Config.deeplUseInFormalTranslation ? 'prefer_less' : 'default'
        },
      }).then(({ data }) => data)
    
      return this.transform(res.translations, options)
    }
    catch (err) {
      log(false, err)
    
      throw err
    }
    }
  2. add a option to the config.ts like
    static get deeplUseFreeApiEntry() {
    return this.getConfig<boolean>('translate.deepl.useFreeApiEntry')
    }

    for example:

    static get deeplUseInFormalTranslation () {
    return this.getConfig<boolean>('translate.deepl.deeplUseInFormalTranslation ')
    }
  3. Add a description to the locales json

That would be really great if this feature could be included.

came commented 1 year ago

How did you build it in locally? It is super annoying to change German Sie to Du again and again. So, yes, please make this configurable as well 😄

Dumdidum12 commented 1 year ago

I did'nt build it locally. I've just changed the code in the windows extension folder. user->.vscode->extensions Is not a big thing :)