From f57339ac4299c893bbf6930377413e861ec9537f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=BCnter?= Date: Tue, 16 Jun 2020 12:24:32 +0200 Subject: [PATCH] docs: translate packages --- docs/advanced/create-package.md | 73 ++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/docs/advanced/create-package.md b/docs/advanced/create-package.md index e8b08e0..9821690 100755 --- a/docs/advanced/create-package.md +++ b/docs/advanced/create-package.md @@ -89,4 +89,75 @@ You have to replace `wp-reactjs-multi-starter` with your names. ## Localization -A package can also be localized with commands [`yarn i18n:backend` and `yarn i18n:generate:frontend`](../usage/available-commands/package.md#localization). All `.pot` files will be generated to `languages`. If you consume a package via `enqueueComposerScript` and `composer require` all localization files are **automatically** loaded to the WordPress runtime, you do not have to manually load them! +A package can also be localized with commands [`yarn i18n:backend` and `yarn i18n:generate:frontend`](../usage/available-commands/package.md#localization). All `.pot` files will be generated to `languages`. If you consume a package via `enqueueComposerScript` and `composer require` all localization files are **automatically** loaded to the WordPress runtime, you do not have to manually load them (Provider)! But, you still need to register the hooks manually as explained below (Consumer). + +### PHP Consumer + +First, you need to create a new file `/packages/your-package/src/Localization.php` with the following content: + +```php +hooks(); +``` + +### TypeScript Consumer + +In your TypeScript coding it is much more easier to consume the translations: + +```tsx +import { createLocalizationFactory } from "@wp-react-multi-starter/utils"; + +const { __, _i /* [...] */ } = createLocalizationFactory(`${process.env.rootSlug}-${process.env.slug}`); +```