summaryrefslogtreecommitdiff
path: root/modules_v4
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2019-03-13 15:17:03 +0000
committerGreg Roach <fisharebest@webtrees.net>2019-03-13 15:17:03 +0000
commitd37db671e2f4b9f27d817b54a435ecf154a67a6b (patch)
tree475cd8dda9bb64eaf9b2e8d32c1464233356402a /modules_v4
parentb0c01d0c28a4ee291803e9f36bcb20e3f916c3da (diff)
downloadwebtrees-d37db671e2f4b9f27d817b54a435ecf154a67a6b.tar.gz
webtrees-d37db671e2f4b9f27d817b54a435ecf154a67a6b.tar.bz2
webtrees-d37db671e2f4b9f27d817b54a435ecf154a67a6b.zip
Allow custom modules to provide translations
Diffstat (limited to 'modules_v4')
-rw-r--r--modules_v4/example.disable/module.php68
1 files changed, 58 insertions, 10 deletions
diff --git a/modules_v4/example.disable/module.php b/modules_v4/example.disable/module.php
index 09ca81b662..8f94cceb85 100644
--- a/modules_v4/example.disable/module.php
+++ b/modules_v4/example.disable/module.php
@@ -4,16 +4,17 @@ namespace MyCustomNamespace;
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Contracts\UserInterface;
+use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Module\AbstractModule;
use Fisharebest\Webtrees\Module\ModuleCustomInterface;
use Fisharebest\Webtrees\Module\ModuleCustomTrait;
use Fisharebest\Webtrees\Tree;
-use Fisharebest\Webtrees\View;
/**
* Example module
*/
-return new class extends AbstractModule implements ModuleCustomInterface {
+return new class extends AbstractModule implements ModuleCustomInterface
+{
use ModuleCustomTrait;
/**
@@ -99,15 +100,62 @@ return new class extends AbstractModule implements ModuleCustomInterface {
if (!Auth::isAdmin($user) && $tree !== null) {
return;
}
+ }
+
+ /**
+ * Additional/updated translations.
+ *
+ * @param string $language
+ *
+ * @return string[]
+ */
+ public function customTranslations(string $language): array
+ {
+ // Here we are using an array for translations.
+ // If you had .MO files, you could use them with:
+ // return (new Translation('path/to/file.mo'))->asArray();
+
+ switch ($language) {
+ case 'en-AU':
+ case 'en-GB':
+ case 'en-US':
+ return $this->englishTranslations();
- // Here is also a good place to register any views (templates) used by the module.
- // This command allows the module to use: view($this->name() . '::', 'fish')
- // to access the file ./resources/views/fish.phtml
- View::registerNamespace($this->name(), __DIR__ . '/resources/views/');
+ case 'fr':
+ case 'fr-CA':
+ return $this->frenchTranslations();
- // We can also provide replacements for existing views (which use an empty namespace).
- // Note that you can also replace views in other modules.
- View::registerCustomView('::individual-page', $this->name() . '::my-individual-page');
- View::registerCustomView('::layouts/administration', $this->name() . '::layouts/my-administration');
+ default:
+ return [];
+ }
+ }
+
+ /**
+ * @return array
+ */
+ protected function englishTranslations(): array
+ {
+ // Note the special characters used in plural and context-sensitive translations.
+ return [
+ 'Individual' => 'Fish',
+ 'Individuals' => 'Fishes',
+ '%s individual' . I18N::PLURAL . '%s individuals' => '%s fish' . I18N::PLURAL . '%s fishes',
+ 'Unknown given name' . I18N::CONTEXT . '…' => '?fish?',
+ 'Unknown surname' . I18N::CONTEXT . '…' => '?FISH?',
+ ];
+ }
+
+ /**
+ * @return array
+ */
+ protected function frenchTranslations(): array
+ {
+ return [
+ 'Individual' => 'Poisson',
+ 'Individuals' => 'Poissons',
+ '%s individual' . I18N::PLURAL . '%s individuals' => '%s poisson' . I18N::PLURAL . '%s poissons',
+ 'Unknown given name' . I18N::CONTEXT . '…' => '?poission?',
+ 'Unknown surname' . I18N::CONTEXT . '…' => '?POISSON?',
+ ];
}
};