A module for ProcessWire to export the translations of a module for a selected language as a downloadable CSV file directly from the admin.
ProcessWire's core translation tools work great for editing the translations of one file at a time, but there is no one-click way to export all registered translations of a specific module - especially if its translatable texts are spread across many files (fieldtypes, inputfields, validation rules and so on).
This module is made for module developers who want to ship their modules with language files. Instead of copying the translations of all files into one CSV file by hand, you export them with one click.
Highlights
- Simple admin page under Setup > Language CSV Exporter: select a module, select a language, download
- One CSV file per module and language (
{Module}-{language}-translations.csv) - Correct separation of modules that share one folder (e.g. a main module and a companion module), including modules in subfolders
- Standard ProcessWire CSV format - the file can be imported again via Setup > Languages
- The CSV rows are byte-identical to ProcessWire's own export (no re-parsing, no lost texts)
- No temporary files - the CSV is created in memory and sent directly to the browser
- Works in debug mode (PHP notices and deprecations do not end up in the CSV)
- Own permission (
language-csv-exporter) to control who may export - All texts translatable - German translation included (
languages/de.csv) - Support for RockLanguage (
RockLanguage/DE/) - No third-party dependencies - uses ProcessWire's
LanguagePorterAPI - Unit tests (PHPUnit) and WireTests for the live environment included
Requirements
- PHP>=7.2
- ProcessWire>=3.0.264
- LanguageSupport (multi-language support enabled)
Installation
Manual installation
Download the module folder and extract it under site/modules.
Make sure that the extracted folder is named LanguageCSVExporter and not LanguageCSVExporter-main or some other name.
Refresh the modules and install the module via the backend (Modules > Refresh, then Install on the Site tab).
Installation via ProcessWire backend
Go to Modules > New > Add Module From URL and enter the URL of the ZIP file:
https://github.com/juergenweb/LanguageCSVExporter/archive/refs/heads/main.zip
Usage
- Go to Setup > Language CSV Exporter
- Select the module whose translations you want to export
- Select the language
- Click Download translations as CSV
Your browser downloads a CSV file named after the module and the language, for example
FrontendForms-de-translations.csv.
The export contains all translation files of the selected language that belong to the module: the files listed in Setup > Languages > (language) ("Site Translation Files" / "Core Translation Files") and translation files that only exist in the files folder of the language without being listed there - for example files copied by RockLanguage.
The CSV format
The exported file uses ProcessWire's standard translation CSV format (as produced by LanguagePorter::exportCsv()):
| Column | Description |
|---|---|
en | The original, English source text |
de (or the name of the exported language) | The translated text |
description | An optional translator note, if one was set |
file | The relative path of the source file the text was found in |
hash | An internal hash ProcessWire uses to match the text with its source |
This is the same format used by ProcessWire's own language import/export tools, so the file can be handed off for translation and imported again via Setup > Languages.
Modules that share one folder
Some modules ship as a pair - a main module plus a companion module - both living in the same folder (for example
site/modules/FrontendForms/ might contain FrontendForms.module and FrontendFormsManager.module). ProcessWire's
own CSV export can only filter by folder, so exporting one of these modules would also include the translations of
the other one.
This module looks at every module (installed or not) whose file lives inside the folder of the selected module:
- Modules in a subfolder (e.g.
site/modules/FrontendForms/SubModules/FooBar/FooBar.module) own this whole subfolder. It is always excluded - export that module separately. - Among the modules directly in the same folder, one is the primary module. Its export includes all files in
the folder except the other modules' own files and subfolders. It is determined in this order:
- it is the only module in the folder,
- the folder name equals its class name (case-insensitive),
- the folder name starts with its class name (e.g. a GitHub download
FrontendForms-main/), - its class name is the prefix of all other class names in the folder (e.g.
FrontendFormsvs.FrontendFormsManager).
- Every other module in the folder is a guest module. Its export contains only its own file.
If no primary module can be determined, every module in the folder only gets its own file, and a warning is shown.
The detection is automatic and needs no configuration.
Translations
All texts of the module are translatable. A German translation is included in languages/de.csv. If your site has
a language named de, the module info page (Modules > Site > Language CSV Exporter) shows the link
install translations. Alternatively, upload the file to the translation files field of the language in
Setup > Languages > (language).
The same translation is included for RockLanguage in RockLanguage/DE/.
The CSV file was created with this module itself, so it can also serve as an example of the export format.
Troubleshooting
"No translations were found ..." - there is no translation file for the module in the selected language yet. Open the files of the module at least once in Setup > Languages > (language) > Find Files to Translate, then export again.
A translation file copied by RockLanguage is not listed on the language page - RockLanguage copies the files directly into the files folder of the language without adding them to the "Site Translation Files" field. The translations work anyway, and this module exports them. To list the file on the language page, select it in Find Files to Translate (click Refresh File List if it is missing) - the existing translations are kept.
Permissions
The module adds the permission language-csv-exporter during the installation. Only users (or roles) with this
permission can open the export page. The permission is removed automatically when the module is uninstalled.
Tests
The tests folder contains unit tests (PHPUnit, run without ProcessWire) and WireTests (run inside a real
ProcessWire installation). The unit tests run automatically on GitHub Actions for every push.
cd tests
composer install
vendor/bin/phpunitphp index.php test site/modules/LanguageCSVExporter/tests/LanguageCSVExporter.test.phpSee tests/README.md for the requirements and what is tested.
Coding standard
The code follows PSR-12. It can be checked with PHP_CodeSniffer:
phpcs --standard=PSR12 --extensions=module/php LanguageCSVExporter.moduleTranslatable texts longer than 120 characters are kept on one line (ProcessWire finds translatable texts only in
single-line calls), so these lines are marked with // phpcs:ignore Generic.Files.LineLength.TooLong.
License
MIT License (see LICENSE.md) - feel free to use in both personal and commercial projects.
More modules by juergen
- FrontendForms by juergen
FrontendLoginRegister
User login/registration component for ProcessWire using the FrontendForms module.9FrontendLoginRegister by juergenOpeninghours
Fieldtype that stores opening hours for each day of the week (including additional input field for holidays)6FieldtypeOpeningHours by juergenFrontendContact
Simple configurable and expandable contact form for ProcessWire based on the FrontendForms module.5FrontendContact by juergenImage Placeholder
A configurable module for creating placeholder images by using TrueTypeFonts for the placeholder text3JkImagePlaceholder by juergenPublish/Unpublish pages
Publish/unpublish, delete or move pages depending on dates and times using LazyCron.3JkPublishPages by juergenFieldtype Object Dimensions
Fieldtype to store length, width, height and to calculate and store the volume and area of an object.2FieldtypeObjectDimensions by juergenSnowFallAnimation
Module for creating and animating snowflakes on a web page using HTML5 canvas and JavaScript classes.2Added 11 months ago by juergenVideo Files
Field that stores one or more self-hosted video files, with title, duration, dimensions, tags and reuse across pages.1Added 1 week ago by juergen
Install and use modules at your own risk. Always have a site and database backup before installing new modules.