API-only Rails app for managing glossaries, terms, and translations.
- Ruby 4.0.0
- Bundler
- SQLite3
bundle install
bundle exec rails db:setupbundle exec rails serverSet the secret key base:
export SECRET_KEY_BASE=your_secret_key_baseGenerate one with:
bundle exec rails secretbundle exec rails testPOST /glossariescreate a glossaryGET /glossaries/:idfetch a glossary with termsGET /glossarieslist glossaries with termsPOST /glossaries/:id/termscreate a term in a glossaryPOST /translationscreate a translationGET /translations/:idfetch a translation with highlighted terms
- Glossaries are unique per
source_language_code+target_language_code. - Language codes must be valid ISO 639-1 values (see
config/iso-639-1.csv). - Terms require non-blank
source_termandtarget_term. - Translations require
source_language_code,target_language_code, andsource_text. source_textis limited to 5000 characters.- When
glossary_idis provided, translation language codes must match the glossary.
- 422:
{ "errors": ["..."] } - 404:
{ "error": "Not Found" }
Create a glossary:
curl -X POST http://localhost:3000/glossaries \
-H 'Content-Type: application/json' \
-d '{"glossary":{"source_language_code":"en","target_language_code":"fr"}}'Create a term:
curl -X POST http://localhost:3000/glossaries/1/terms \
-H 'Content-Type: application/json' \
-d '{"term":{"source_term":"recruitment","target_term":"recrutement"}}'Create a translation:
curl -X POST http://localhost:3000/translations \
-H 'Content-Type: application/json' \
-d '{"translation":{"source_language_code":"en","target_language_code":"fr","source_text":"This is a recruitment task.","glossary_id":1}}'Fetch a translation (with highlighted terms):
curl http://localhost:3000/translations/1Example response:
{
"id": 1,
"source_language_code": "en",
"target_language_code": "fr",
"source_text": "This is a <HIGHLIGHT>recruitment</HIGHLIGHT> task.",
"glossary_id": 1,
"matching_terms": [
{
"id": 1,
"source_term": "recruitment",
"target_term": "recrutement"
}
]
}docker build -t translator_api .
docker run --rm -p 3000:3000 -v "$(pwd)/db:/app/db" translator_apiIf you need to initialize the database inside the container:
docker run --rm -p 3000:3000 -v "$(pwd)/db:/app/db" translator_api bundle exec rails db:prepare