Skip to content

Instantly share code, notes, and snippets.

@ScullWM
Last active April 5, 2016 10:17
Show Gist options
  • Save ScullWM/2ccee0c2d126b9515e7f to your computer and use it in GitHub Desktop.
Save ScullWM/2ccee0c2d126b9515e7f to your computer and use it in GitHub Desktop.
translation-server

Install translation-server

  1. Download directly the phar here: https://github.com/ScullWM/translation-server/tree/dev_dead/build/translation-server.phar (DeadKey Edition) It's a fork from mmoreram/translation-server (Look like not maintained anymore)

  2. Move it to your bin path: cp build/translation-server.phar /usr/local/bin/translation-server

Configure your project

Create a .translation.ymlfile in app/Resources/translations

master_language: en
languages:
    - en
    - fr
    - da
paths:
	- app/Resources/translations
	- src/Xeonys/Bundle/GestionCentraleBundle/Resources/translations/
	- ...
export_path: /tmp

Use commands

See translation status (and export them)

translation-server translation:server:view --config="app/Resources/translations/"

Return:

[Trans Server] Command started at Fri, 18 Mar 2016 09:21:07 +0100
[Trans Server] Translations for [fr] is 100% completed. 0 missing
[Trans Server] Translations for [en] is 98.84% completed. 25 missing
[Trans Server] Translations for [da] is 94.98% completed. 108 missing
[Trans Server] Command finished in 2083 milliseconds
[Trans Server] Max memory used: 16515072 bytes

If you have missing translation, add the --export option to get the listing of missing command for each locales:

translation-server translation:server:view --config="app/Resources/translations/" --export

[Trans Server] Command started at Fri, 18 Mar 2016 09:24:48 +0100
[Trans Server] Translations for [fr] is 100% completed. 0 missing
[Trans Server] Export missing file in /tmp/missing.fr.json for fr
[Trans Server] Translations for [en] is 98.84% completed. 25 missing
[Trans Server] Export missing file in /tmp/missing.en.json for en
[Trans Server] Translations for [da] is 94.98% completed. 108 missing
[Trans Server] Export missing file in /tmp/missing.da.json for da
[Trans Server] Command finished in 2095 milliseconds
[Trans Server] Max memory used: 16252928 bytes

Note that json file are dumped in you export path /tmp/missing.en.json

{
  "105": "widget.dropzoneModal.errorExtension",
  "1833": "xeonys.gestioncentrale.user.new",
  "1834": "xeonys.gestioncentrale.user.activation",
  "1835": "xeonys.gestioncentrale.user.modification",
  "1836": "xeonys.gestioncentrale.user.delete",
  "1837": "xeonys.gestioncentrale.user.deactivate",
  "1838": "xeonys.gestioncentrale.user.renew_password",
  "1839": "xeonys.gestioncentrale.module.new",
  "1840": "xeonys.gestioncentrale.module.delete",
  "1841": "xeonys.gestioncentrale.module.unsubscription",
  "1842": "xeonys.gestioncentrale.group.new",
  "1866": "dashboard.dematerialization.ajax.error",
  "1867": "dashboard.dematerialization.ajax.timeout",
  "1873": "dashboard.dematerialization.am",
  "1874": "dashboard.dematerialization.po",
  "1875": "dashboard.dematerialization.agency",
  "1876": "dashboard.dematerialization.pole",
  "1878": "dashboard.equipment.accountingApp_title",
  "1880": "dashboard.equipment.checkoutApp_title",
  "1886": "dashboard.equipment.dematApp_title",
  "1889": "dashboard.equipment.expenseReportApp_title",
  "1906": "dashboard.equipment.payrollApp_title",
  "1911": "dashboard.filters.year",
  "2034": "form.moduleStoreInformation.title.external",
  "2068": "mail.see_now"
}

Auto Translate key

Using google translation to translate missing keys (translations are based on the master_language defined in our .translation.yml)

translation-server translation:server:guess --config="app/Resources/translations/"

[Trans Server] Command started at Fri, 18 Mar 2016 09:30:15 +0100
[Trans Server] Language : en
[Trans Server] Key : dashboard.dematerialization.ajax.error
[Trans Server] Original : Les données sont en cours d'actualisation. Veuillez réessayer ou revenir plus tard.
[Trans Server] Translation : The data is being updated. Please try again or come back later.

[Trans Server] Language : en
[Trans Server] Key : xeonys.gestioncentrale.module.new
[Trans Server] Original : Nouveau module
[Trans Server] Translation : new Module

[Trans Server] Language : da
[Trans Server] Key : collaborator.editStepInformations.roles_availables
[Trans Server] Original : Roles disponibles
[Trans Server] Translation : roller til rådighed

[Trans Server] No more translations for you!
[Trans Server] Command finished in 3015 milliseconds
[Trans Server] Max memory used: 17039360 bytes

Search Dead key

NEW! Big help to find useless key in your translation files that are not in used anymore in your project.

translation-server translation:server:dead --config="app/Resources/translations/

This can takes severals minutes

Optionnal: --path src/ Define directory to search the translation.

This command dump a file in your export path like /tmp/dead.fr.yml. It WILL ONLY HELP YOU to find this dead keys. Generate key like 'user.status.label_' . $userStatus won't be found, double verification before delete them. Only your master language will be check.

Filtering by language

You can filter all results by language using the option [--language|-l] in all your commands.

translation-server translation:server:guess --config="app/Resources/translations/" -l da

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment