Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get it to work with .NET 9 #15

Open
jh197033 opened this issue Jan 24, 2025 · 0 comments
Open

Cannot get it to work with .NET 9 #15

jh197033 opened this issue Jan 24, 2025 · 0 comments

Comments

@jh197033
Copy link

I have a simple test docker image built with the following compose file:

services:
libretranslate:
container_name: libretranslate
image: libretranslate/libretranslate:latest
restart: unless-stopped
ports:
- "5000:5000"
command: --api-keys --disable-web-ui --req-limit 0
environment:
- LT_API_KEYS_DB_PATH=/app/db/api_keys.db # Same result as db/api_keys.db or ./db/api_keys.db
volumes:
- libretranslate_api_keys:/app/db/api_keys.db

volumes:
libretranslate_api_keys:

In my .NET project I have added the nuget ref to LibreTranslate.Net and added using LibreTranslate.Net;

Then added the following code to call translate:

var libreTranslate = new LibreTranslate.Net.LibreTranslate("http://localhost:5000");
var englishText = "Hello World!";
var getSupportedLanguagesAsyncTask = libreTranslate.GetSupportedLanguagesAsync();
System.Threading.Tasks.Task.Run(() => getSupportedLanguagesAsyncTask).Wait();
var supportedLanguages = getSupportedLanguagesAsyncTask.Result;
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(supportedLanguages, Newtonsoft.Json.Formatting.Indented));
var TranslateAsyncTask = libreTranslate.TranslateAsync(new Translate()
{
ApiKey = "MySecretApiKey",
Source = LanguageCode.English,
Target = LanguageCode.Spanish,
Text = englishText
});

var spanishText = TranslateAsyncTask.Result; always returns null, am I missing some steps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant