]> BookStack Code Mirror - bookstack/blob - app/Translation/LocaleDefinition.php
Vectors: Added command to regenerate for all
[bookstack] / app / Translation / LocaleDefinition.php
1 <?php
2
3 namespace BookStack\Translation;
4
5 class LocaleDefinition
6 {
7     public function __construct(
8         protected string $appName,
9         protected string $isoName,
10         protected bool $isRtl
11     ) {
12     }
13
14     /**
15      * Provide the BookStack-specific locale name.
16      */
17     public function appLocale(): string
18     {
19         return $this->appName;
20     }
21
22     /**
23      * Provide the ISO-aligned locale name.
24      */
25     public function isoLocale(): string
26     {
27         return $this->isoName;
28     }
29
30     /**
31      * Returns a string suitable for the HTML "lang" attribute.
32      */
33     public function htmlLang(): string
34     {
35         return str_replace('_', '-', $this->isoName);
36     }
37
38     /**
39      * Returns a string suitable for the HTML "dir" attribute.
40      */
41     public function htmlDirection(): string
42     {
43         return $this->isRtl ? 'rtl' : 'ltr';
44     }
45
46     /**
47      * Translate using this locate.
48      */
49     public function trans(string $key, array $replace = []): string
50     {
51         return trans($key, $replace, $this->appLocale());
52     }
53 }