Skip to content

Commit f861e91

Browse files
committed
Update readme
1 parent c991a01 commit f861e91

File tree

1 file changed

+43
-18
lines changed

1 file changed

+43
-18
lines changed

README.md

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ This plugins provides:
1919

2020
## Installation
2121

22-
```
22+
```bash
2323
composer require admad/cakephp-i18n
2424
```
2525

2626
## Usage
2727

2828
Load the plugin by running command:
2929

30-
```
30+
```bash
3131
bin/cake plugin load ADmad/I18n
3232
```
3333

@@ -63,11 +63,16 @@ will be automatically added based on current URL.
6363

6464
When connecting the routes you can use `lang` key in options to provide regular
6565
expression to match only languages which your app supports. Or your can set
66-
config value `I18n.languages` which the route class will use to auto generate
66+
config value `I18n.languages`, which the route class will use to auto generate
6767
regex for `lang` element matching:
6868

6969
```php
70-
Configure::write('I18n.languages', ['en', 'fr', 'de']);
70+
// In your config/app.php
71+
...
72+
'I18n' => [
73+
'languages' => ['en', 'fr', 'de']
74+
]
75+
...
7176
```
7277

7378
Note: `I18nRoute` extends core's `DashedRoute` so the URL fragments will be
@@ -127,21 +132,21 @@ The middleware does basically two things:
127132

128133
### DbMessagesLoader
129134

130-
By default CakePHP using `.po` files to store the static string translations. If
131-
for whatever reason you don't want to use `.po` files you can use the `DbMessagesLoader`
132-
class to store the translation messaged in database instead. Personally I belive
133-
having the messages in a table instead of `.po` files make it much easier to
134-
make a web interface for managing translations.
135+
By default CakePHP uses `.po` files to store the static string translations. If
136+
for whatever reason you can't/don't want to use `.po` files, you can use the
137+
`DbMessagesLoader` to store the translation messages in the database instead.
138+
Personally I belive having the messages in a table instead of `.po` files makes
139+
it much easier to make a web interface for managing translations.
135140

136-
To use this class first create the database table using sql file provided in the
137-
plugin's `config` folder.
141+
To use this class first create the `i18n_messages` database table using the sql
142+
file provided in the plugin's `config` folder.
138143

139144
Add code similar to what's shown below in your app's `config/bootstrap.php`:
140145

141146
```php
142147
// NOTE: This is should be done below Cache config setup.
143148

144-
// Configure I18n to use DbMessagesLoader for default domain. You need to do
149+
// Configure `I18n` to use `DbMessagesLoader` for the `default` domain. You need to do
145150
// this for each domain separately.
146151
\Cake\I18n\I18n::config('default', function ($domain, $locale) {
147152
return new \ADmad\I18n\I18n\DbMessagesLoader(
@@ -151,17 +156,37 @@ Add code similar to what's shown below in your app's `config/bootstrap.php`:
151156
});
152157
```
153158

154-
You can use `admad/i18n extract` command to extract the translation message from your
155-
code files and populate the translations table. Updating the db records with
159+
Now you can use the translation functions like `__()` etc. as you normally would.
160+
The `I18n` class will fetch the required translations from the `i18n_messages`
161+
table instead of `.po` files.
162+
163+
Use the `admad/i18n extract` command to extract the translation messages from your
164+
code files and populate the translations table. Updating the database records with
156165
translations for each language is upto you.
157166

158-
```
167+
```bash
159168
bin/cake admad/i18n extract
160169
```
161170

162-
Now you can use the translation functions like `__()` etc. as you normally would.
163-
The `I18n` class will fetch the required translations from the database instead
164-
of `.po` files.
171+
The extract command needs the list of languages/locales to populate the `i18n_messages`
172+
table. This can be done by setting the `I18n.languages` config **or** by specifying
173+
the languages list using the `languages` option.
174+
175+
```php
176+
// In your config/app.php
177+
...
178+
'I18n' => [
179+
'languages' => ['en', 'fr', 'de']
180+
]
181+
...
182+
```
183+
184+
```bash
185+
bin/cake admad/i18n extract --languages en,fr,de
186+
```
187+
188+
You can run the command multiple times as needed. It will add new messages it
189+
finds to the tables, keeping the ones already present untouched.
165190

166191
### TimezoneWidget
167192

0 commit comments

Comments
 (0)