Skip to content

Commit f143ecf

Browse files
Gummibeergitbook-bot
authored andcommitted
GitBook: [master] 3 pages modified
1 parent aaf81c1 commit f143ecf

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ echo $post->translate('fr')->title; // Mon premier post
5353

5454
* [How To Add Multilingual Support to Eloquent](https://laravel-news.com/how-to-add-multilingual-support-to-eloquent)
5555
* [How To Build An Efficient and SEO Friendly Multilingual Architecture For Your Laravel Application](https://mydnic.be/post/how-to-build-an-efficient-and-seo-friendly-multilingual-architecture-for-your-laravel-application)
56+
* [How to Add Multi-Language Models to Laravel QuickAdminPanel](https://quickadminpanel.com/blog/how-to-add-multi-language-models-to-laravel-quickadminpanel/)
5657

5758
## Add-Ons
5859

docs/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
* [Methods](usage/methods.md)
1212
* [Scopes](usage/scopes.md)
1313
* [Fallback locale](usage/fallback-locale.md)
14+
* [Locales helper](usage/locales-helper.md)
1415

docs/usage/locales-helper.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Locales helper
2+
3+
In addition to the trait we also provide a helper class `\Astrotomic\Translatable\Locales` it's a singleton service available as `translatable.locales` and `\Astrotomic\Translatable\Locales` .
4+
This helper manages all locales available for translation and provides several methods.
5+
6+
This class also implements the `ArrayAccess` interface to allow you to use it like a normal array.
7+
8+
## Methods
9+
10+
### load\(\)
11+
12+
This method will \(re\)load all locales from the `translatable.locales` config - it's called during service instantiation so you will only need it if you change the config during runtime.
13+
14+
{% hint style="info" %}
15+
If you don't have to do so to work with other packages we recommend to use the provided methods of this helper service to manipulate the available locales instead of changing the config during runtime.
16+
{% endhint %}
17+
18+
### all\(\)
19+
20+
**Alias:** `toArray()`
21+
22+
Returns all available locales as an array - the structure differs from the config one, the return final generated array with combined country locales.
23+
24+
```php
25+
[
26+
'en',
27+
'de',
28+
'es',
29+
'es-MX',
30+
'es-CO',
31+
]
32+
```
33+
34+
### current\(\)
35+
36+
Returns the current locale string.
37+
38+
### has\(string $locale\)
39+
40+
Checks if the given locale is available in the configured set of locales.
41+
42+
### get\(string $locale\)
43+
44+
Returns the provided locale or `null` if it's not set.
45+
46+
{% hint style="info" %}
47+
At all this isn't really useful except you want to build your own check if a locale is set.
48+
{% endhint %}
49+
50+
### add\(string $locale\)
51+
52+
Adds the given locale to the set of available locales.
53+
54+
{% hint style="info" %}
55+
The set of available locales will keep unique and this method won't throw an exception if the locale is already present.
56+
{% endhint %}
57+
58+
### forget\(string $locale\)
59+
60+
Removes the given locale of the available locales set.
61+
62+
{% hint style="info" %}
63+
This method won't throw an exception if the locale isn't present.
64+
{% endhint %}
65+
66+
### getLocaleSeparator\(\)
67+
68+
Returns the configured `translatable.locale_separator` locale separator used to combine language with country locales.
69+
70+
### getCountryLocale\(string $locale, string $country\)
71+
72+
Returns the formatted country based locale.
73+
74+
### isLocaleCountryBased\(string $locale\)
75+
76+
Checks if the given locale is a country specific locale.
77+
78+
### getLanguageFromCountryBasedLocale\(string $locale\)
79+
80+
Returns the language locale from given country based locale.
81+

0 commit comments

Comments
 (0)