Jump to content

The output from my binary program running on terminal is different from the output from alfred


Recommended Posts

Dear all,

 

I'm working on my own workflow which will translate any language to simplified Chinese using the Asure Translator API.

 

I've created a rust client to do this, running it on command line looks like this:

```

$ ./translator dignité
text:dignité
from:fr to:zh-Hans

{"items":[{"title":"尊严","subtitle":"fr","arg":"尊严"}]}

```

The text line and from line are printing to stderr, just for debugging purpose. Here we can see we successfully translate the word from french to simplified Chinese

 

However, when I call this program in alfred workflow (script filter), the results is different. I'm attaching the debugging log here

 

```

[12:20:38.362] Translate[Script Filter] Queuing argument 'dignité'
[12:20:38.998] Translate[Script Filter] Script with argv '(null)' finished
[12:20:38.999] STDERR: Translate[Script Filter] text:dignité
from:en to:zh-Hans
[12:20:39.001] Translate[Script Filter] {"items":[{"title":"dignité","subtitle":"en","arg":"dignité"}]}
[12:20:40.981] Translate[Script Filter] Processing complete
[12:20:40.982] Translate[Script Filter] Passing output 'dignité' to Copy to Clipboard

```

 

Here, we can see the text line is correct, my program accept input parameter as dignité

However, for this same input, it's recognizing as en rather than fr, and its result is not translating the word

 

I tried this process many times. Every time I call the program using terminal, it shows the correct output, recognizing this French word and every time I called it through alfred, it shows the wrong results, not translating it.

 

Anyone has any idea what's the possible reason?

 

My script filter script is:

```

./translator '{query}'

```

 

Link to comment
6 hours ago, RunningBugs said:

Anyone has any idea what's the possible reason?

 

How does your program determine what the source language is? Is your shell's locale set to French? Alfred's isn't.

 

Another possibility is Unicode normalisation. Try normalising the text to NFC form before using it.

Link to comment
3 hours ago, deanishe said:

 

How does your program determine what the source language is? Is your shell's locale set to French? Alfred's isn't.

 

Another possibility is Unicode normalisation. Try normalising the text to NFC form before using it.

 

Thank you so much! I solved the problem by normalizing the text to NFC!

 

My program determine the source language using Asure's Translator API, there's detect API, translation API ( for sentences ) and Dictionary API.

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...