The LWTranslator project is a web-based application built with Blazor for the frontend and a .NET 8 Web API for the backend. This application allows users to translate text between languages by leveraging the Google Translate API. It includes features for selecting source and target languages, entering text, and retrieving translations.
- Language Selection: Users can select both the source and target languages for translation from a dropdown list of available languages.
- Text Translation: Users can enter text to be translated, which is then processed and translated via the Google Translate API.
- Real-Time Translation: The application sends requests to the Web API, which interacts with Google Translate, providing translated text instantly upon request.
- LW.Client: Contains the Blazor frontend application that provides the user interface and handles interactions.
- LW.Api: Contains the .NET 8 Web API backend, which processes translation requests and interacts with the Google Translate API.
- Docker: Ensure Docker is installed and running.
- Google Translate API Key: A valid Google Translate API key is required for translation services.
To enable Google Translate API integration, set an environment variable named GOOGLE_TRANSLATE_API_KEY
with your Google Translate API key. You can set this variable either on your machine or directly in the Dockerfile.
-
On Your Computer:
- On Windows:
set GOOGLE_TRANSLATE_API_KEY=your_api_key_here
- On macOS/Linux:
export GOOGLE_TRANSLATE_API_KEY=your_api_key_here
- On Windows:
-
In the Dockerfile: You can also add the
GOOGLE_TRANSLATE_API_KEY
environment variable in each service's Dockerfile to pass the key directly to the container.ENV GOOGLE_TRANSLATE_API_KEY=your_api_key_here
-
Clone the Repository:
git clone https://github.com/joseasync/LWTranslator.git cd LWTranslator
-
Build and Run the Docker Containers: Use Docker Compose to build and run the containers for both the Blazor frontend and the Web API.
docker-compose up --build
- Blazor Application: Runs on http://localhost:7200
- Web API: Runs on http://localhost:8080
-
Access the Application:
- Open a browser and navigate to http://localhost:7200 to start using the translation application.
- Registration:
http://localhost:7200/register
- Login:
GET http://localhost:7200/login
- Translator:
http://localhost:7200/translator
- URL:
GET /translator/languages/available
- Description: Retrieves a list of languages supported by the Google Translate API.
-
Login: Use the access token for authentication.
-
URL:
POST /translator/generate
-
Description: Takes source and target languages along with the text to be translated and returns the translated text.
-
Request Body:
{ "fromLanguage": "en-US", "toLanguage": "fr-FR", "inputText": "Hello, world!" }
-
Response:
{ "language": "fr-FR", "text": "Bonjour, le monde!" }
- Error Handling: The application includes error handling and logs errors in case of unsuccessful API calls.
- Testing: When testing locally without Docker, ensure the
GOOGLE_TRANSLATE_API_KEY
is correctly set in your environment.