Skip to content

Commit ecc5000

Browse files
committed
docs: add localization guide and fix typo in DNS setup
1 parent ea9853e commit ecc5000

3 files changed

Lines changed: 75 additions & 1 deletion

File tree

docs/.vitepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default defineConfig({
2929
{text: 'Setting up', link: '/plugin-development/setting-up'},
3030
{text: 'Running tests', link: '/plugin-development/running-tests'},
3131
{text: 'Debugging', link: '/plugin-development/debugging'},
32+
{text: 'Localization', link: '/plugin-development/localization'},
3233
]
3334
},
3435
{

docs/introduction/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ By doing these few steps you now have a functional Filament app with our Eclipse
1818
1919
## DNS setup
2020
When using Lando for local development, the project domain will be hosted at a `*.lndo.site` subdomain.
21-
If you are happy not happy with this, or if for some reason this does not work for you (e.g. disabled [DNS rebinding](https://docs.lando.dev/help/dns-rebind.html)), we recommend you set up DNSMasq.
21+
If you are not happy with this, or if for some reason this does not work for you (e.g. disabled [DNS rebinding](https://docs.lando.dev/help/dns-rebind.html)), we recommend you set up DNSMasq.
2222
### Linux
2323
1. Install it:
2424
- with dnf (Fedora, RHEL...)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Localization (L10n)
2+
3+
Localization is a crucial aspect of plugin development, as it allows your plugin to be used by a global audience.
4+
5+
## Laravel basics
6+
### Setting the default locale
7+
The default locale is set in the application configuration file, which is located at `config/app.php`. The default locale is defined by the `locale` key.
8+
9+
You can also change the default locale by setting the `APP_LOCALE` environment variable in the `.env` file.
10+
11+
### Getting the current locale
12+
You can get the current locale using the `app()->getLocale()` method.
13+
14+
### Changing the current locale
15+
You can change the current locale using the `app()->setLocale()` method.
16+
17+
Read more on the Laravel documentation localization page [here](https://laravel.com/docs/localization).
18+
19+
## Available locales
20+
The first thing to note is that the available locales are provided with the common package; therefore, you must set your locales in the `eclipse-common` config file.
21+
22+
```php
23+
/*
24+
* Available locales for the application.
25+
* Can be a list (array) of locale codes or a closure that returns such an array.
26+
*/
27+
'available_locales' => function () {
28+
return ['en', 'sl'];
29+
},
30+
```
31+
As the comment above states, you can either provide a list of locales or a closure that returns such a list if you need to dynamically set the locales.
32+
33+
## L10nHelper
34+
The `L10nHelper` class is provided by the common package and provides a set of static methods for localization.
35+
36+
### `getAvailableLocales()`
37+
The `getAvailableLocales()` method returns an associative array of available locales, where the element key is always the same as the value.
38+
39+
**Example:**
40+
```php
41+
[
42+
'en' => 'en',
43+
'sl' => 'sl',
44+
]
45+
```
46+
47+
### `getLocaleOptions()`
48+
The `getLocaleOptions()` method returns an associative array of locales, where the element key is the locale code and the element value is the language name. This is useful for building select boxes or similar UI elements.
49+
50+
**Example:**
51+
```php
52+
[
53+
'en' => 'English',
54+
'sl' => 'Slovenian',
55+
]
56+
```
57+
::: tip IMPORTANT
58+
The language name is provided by the `intl` PHP extension; therefore, you must have it installed to use this method.
59+
:::
60+
61+
### `getLanguageName(string $code, bool $include_code = false)`
62+
The `getLanguageName()` method returns the language name from the language code.
63+
64+
**Examples:**
65+
```php
66+
L10nHelper::getLanguageName('en') // English
67+
L10nHelper::getLanguageName('sl') // Slovenian
68+
L10nHelper::getLanguageName('sl', true) // Slovenian (sl)
69+
L10nHelper::getLanguageName('xx') // xx
70+
```
71+
1. If the `intl` PHP extension is installed, the method uses the `\Locale` class to get the language name.
72+
2. Otherwise, it returns the language code.
73+

0 commit comments

Comments
 (0)