m9dfukc / deepl-alfred-workflow

DeepL translations for Alfred
MIT License
75 stars 3 forks source link

Special chars seem to be an issue - f.e. `ü` #11

Closed m9dfukc closed 6 years ago

m9dfukc commented 6 years ago

scenario: we wanna translate gültigkeit from german to english, the source language should be detected automatically (german) and the default target language is set in our script (english).

what happends: the automatic source language detection fails and is set to english (?), as a translation result for gültigkeit we get gültigkeit, so basically the same as the input.

what should happen: as a translation result we should get validity.

what might be the reason: if gueltigkeit (ue instead of ü) is the input we wann get translated, the result validity shows up, thus it seems somehow related to the ü special char character.

kevkol commented 6 years ago

Replacing the script filter in the workflow with the following should do the trick temporary:

require_once( __DIR__ . '/deepl.php' );

// DE, EN, FR, ES, IT, NL, PL are available
// or use > {LANG_CODE} to force the translation language

$default_language = 'DE';
$deepl = new DeeplTranslate($default_language);

$arg = "{query}";
$arg = str_replace("ä", "ae", $arg);
$arg = str_replace("ü", "ue", $arg);
$arg = str_replace("ö", "oe", $arg);
$arg = str_replace("Ä", "Ae", $arg);
$arg = str_replace("Ü", "Ue", $arg);
$arg = str_replace("Ö", "Oe", $arg);
$arg = str_replace("ß", "ss", $arg);

echo $deepl->translate($arg);