Skip to content

Glossary pages

phil/translation-bundle

The glossary of a pair of languages is edited on screen: a table of its terms, a form that adds or changes a term, a button that removes one, the export of the glossary as TBX and the import of a TBX file. Every change goes through the bundle's Glossaries, as the application's own code would.

Routes

RouteMethod and pathDoes
phil_translation_glossaryGET /glossary/{source}/{target}The terms and the form
phil_translation_glossary_savePOST /glossary/{source}/{target}action=save adds or changes a term, action=remove removes one, then back with a 303
phil_translation_glossary_exportGET /glossary/{source}/{target}/tbxThe glossary as a TBX attachment
phil_translation_glossary_importPOST /glossary/{source}/{target}/tbxA TBX file put into the glossary, then back with the count

The routes come with the screen's, from config/routes.php, after them: a document named glossary keeps its screen.

Who may edit

TranslationPolicy::canEditGlossary($source, $target) answers for the current user. Without a policy, the pages answer 404; for a user it refuses, or the same language twice, 403; for a language that is not a tag, 404. Forms from another site are refused as on the screen.

The form

FieldMeaning
termThe term in the source language
formsIts inflected forms, one per line
translationsIts translations, one per line; none keeps the term as it is
translation_formsThe inflected forms of the translations, one per line
forbiddenRefused translations, one per line
case_sensitiveWhether case matters
noteA note for translators

A term without words, or longer than 255 bytes, is refused with 422 and the reason.

TBX

Glossaries::export() writes the terms as they are kept — without the forms an inflector adds — as TBX-Basic, and Glossaries::import() puts the terms of a TBX file of 2019 or 2008 into the glossary: new terms added, terms it has replaced. A file larger than 10 MiB, unreadable, or with a term longer than 255 bytes is refused with 422.

EasyAdmin

An EasyAdmin back office links to the pages, which keep their own routes, forms and layout — the bundle's layout, pointed at a template of the back office:

use Phil\TranslationBundle\Infrastructure\EasyAdmin\TranslationAdmin;

public function configureMenuItems(): iterable
{
    yield from TranslationAdmin::menuItems([['en', 'fr'], ['en', 'fr-CA']]);
}

menuItems() gives one link per pair of languages, labelled Glossary en → fr unless a label with two %s is given, with the icon fa fa-language unless another is. EasyAdmin is suggested, not required.

Inflected forms

With an inflector, the glossary that finds and checks terms adds the forms it makes:

phil_translation:
    inflector: Phil\TranslationMemory\Glossary\RegularPlurals   # the regular plurals of English and French