@sankhyalabs/core-docs 0.0.0-feat-dev-KB-97809.1 → 0.0.0-feat-dev-KB-97809.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/classes/LangUtils.md +78 -13
- package/package.json +1 -1
package/classes/LangUtils.md
CHANGED
@@ -6,6 +6,9 @@
|
|
6
6
|
|
7
7
|
# Class: LangUtils
|
8
8
|
|
9
|
+
A classe `LangUtils` fornece métodos utilitários para gerenciar configurações de
|
10
|
+
idioma, incluindo recuperar, definir e aplicar preferências de idioma.
|
11
|
+
|
9
12
|
## Constructors
|
10
13
|
|
11
14
|
### new LangUtils()
|
@@ -22,9 +25,11 @@
|
|
22
25
|
|
23
26
|
> `static` **ELanguages**: *typeof* `__class`
|
24
27
|
|
28
|
+
Classe estática contendo os códigos de idioma predefinidos.
|
29
|
+
|
25
30
|
#### Source
|
26
31
|
|
27
|
-
src/utils/LangUtils.ts:
|
32
|
+
src/utils/LangUtils.ts:14
|
28
33
|
|
29
34
|
## Methods
|
30
35
|
|
@@ -32,15 +37,21 @@ src/utils/LangUtils.ts:2
|
|
32
37
|
|
33
38
|
> `static` **applyLanguageFromCookie**(): `void`
|
34
39
|
|
35
|
-
Define o atributo lang no
|
40
|
+
Define o atributo `lang` no elemento `<html>` com base no cookie de idioma, se existir.
|
36
41
|
|
37
42
|
#### Returns
|
38
43
|
|
39
44
|
`void`
|
40
45
|
|
46
|
+
#### Example
|
47
|
+
|
48
|
+
```ts
|
49
|
+
LangUtils.applyLanguageFromCookie(); // Aplica o idioma do cookie ao elemento `<html>`
|
50
|
+
```
|
51
|
+
|
41
52
|
#### Source
|
42
53
|
|
43
|
-
src/utils/LangUtils.ts:
|
54
|
+
src/utils/LangUtils.ts:123
|
44
55
|
|
45
56
|
***
|
46
57
|
|
@@ -48,17 +59,30 @@ src/utils/LangUtils.ts:69
|
|
48
59
|
|
49
60
|
> `static` `private` **convertLanguage**(`lang`): `string`
|
50
61
|
|
62
|
+
Converte o idioma fornecido para um dos códigos predefinidos.
|
63
|
+
|
51
64
|
#### Parameters
|
52
65
|
|
53
66
|
• **lang**: `string`
|
54
67
|
|
68
|
+
O idioma a ser convertido (ex.: "en", "es", "pt-BR").
|
69
|
+
|
55
70
|
#### Returns
|
56
71
|
|
57
72
|
`string`
|
58
73
|
|
74
|
+
O código de idioma correspondente (ex.: "en_US", "es_ES").
|
75
|
+
|
76
|
+
#### Example
|
77
|
+
|
78
|
+
```ts
|
79
|
+
LangUtils.convertLanguage("en"); // Retorna "en_US"
|
80
|
+
LangUtils.convertLanguage("es-es"); // Retorna "es_ES"
|
81
|
+
```
|
82
|
+
|
59
83
|
#### Source
|
60
84
|
|
61
|
-
src/utils/LangUtils.ts:
|
85
|
+
src/utils/LangUtils.ts:30
|
62
86
|
|
63
87
|
***
|
64
88
|
|
@@ -66,15 +90,25 @@ src/utils/LangUtils.ts:8
|
|
66
90
|
|
67
91
|
> `static` **getHtmlLanguage**(): `string`
|
68
92
|
|
69
|
-
|
93
|
+
RRecupera o valor do atributo `lang` do elemento `<html>`. Se o ambiente
|
94
|
+
estiver em modo de desenvolvimento, o idioma padrão será `"pt_BR"`. Caso
|
95
|
+
contrário, utiliza o idioma do navegador ou `"pt-BR"` como padrão.
|
70
96
|
|
71
97
|
#### Returns
|
72
98
|
|
73
99
|
`string`
|
74
100
|
|
101
|
+
O idioma definido no elemento `<html>` ou o padrão.
|
102
|
+
|
103
|
+
#### Example
|
104
|
+
|
105
|
+
```ts
|
106
|
+
LangUtils.getHtmlLanguage(); // Retorna "pt_BR" no modo desenvolvimento
|
107
|
+
```
|
108
|
+
|
75
109
|
#### Source
|
76
110
|
|
77
|
-
src/utils/LangUtils.ts:
|
111
|
+
src/utils/LangUtils.ts:77
|
78
112
|
|
79
113
|
***
|
80
114
|
|
@@ -82,15 +116,27 @@ src/utils/LangUtils.ts:39
|
|
82
116
|
|
83
117
|
> `static` **getLanguage**(): `string`
|
84
118
|
|
85
|
-
Captura
|
119
|
+
Captura o idioma atualmente definido. Primeiro verifica se há um idioma
|
120
|
+
armazenado nos cookies. Caso contrário, utiliza o idioma definido no elemento
|
121
|
+
`<html>`. Se nenhum valor for encontrado nos cookies ou no elemento `<html>`,
|
122
|
+
é utilizada a configuração do navegador. Caso o navegador também não forneça
|
123
|
+
um idioma, o padrão será `"pt_BR"`.
|
86
124
|
|
87
125
|
#### Returns
|
88
126
|
|
89
127
|
`string`
|
90
128
|
|
129
|
+
O idioma definido (ex.: "pt_BR", "en_US").
|
130
|
+
|
131
|
+
#### Example
|
132
|
+
|
133
|
+
```ts
|
134
|
+
LangUtils.getLanguage(); // Retorna o idioma atual
|
135
|
+
```
|
136
|
+
|
91
137
|
#### Source
|
92
138
|
|
93
|
-
src/utils/LangUtils.ts:
|
139
|
+
src/utils/LangUtils.ts:57
|
94
140
|
|
95
141
|
***
|
96
142
|
|
@@ -98,15 +144,23 @@ src/utils/LangUtils.ts:26
|
|
98
144
|
|
99
145
|
> `static` **getLanguageFromCookie**(): `null` \| `string`
|
100
146
|
|
101
|
-
Recupera o valor do cookie de
|
147
|
+
Recupera o valor do cookie de idioma.
|
102
148
|
|
103
149
|
#### Returns
|
104
150
|
|
105
151
|
`null` \| `string`
|
106
152
|
|
153
|
+
O valor do cookie de idioma ou `null` se não existir.
|
154
|
+
|
155
|
+
#### Example
|
156
|
+
|
157
|
+
```ts
|
158
|
+
LangUtils.getLanguageFromCookie(); // Retorna "pt_BR" se o cookie existir
|
159
|
+
```
|
160
|
+
|
107
161
|
#### Source
|
108
162
|
|
109
|
-
src/utils/LangUtils.ts:
|
163
|
+
src/utils/LangUtils.ts:112
|
110
164
|
|
111
165
|
***
|
112
166
|
|
@@ -114,17 +168,28 @@ src/utils/LangUtils.ts:61
|
|
114
168
|
|
115
169
|
> `static` **setHtmlLanguage**(`language`): `void`
|
116
170
|
|
117
|
-
|
118
|
-
e atualiza o cookie de linguagem
|
171
|
+
Define o atributo `lang` no elemento `<html>` e atualiza o cookie de idioma.
|
119
172
|
|
120
173
|
#### Parameters
|
121
174
|
|
122
175
|
• **language**: `string`
|
123
176
|
|
177
|
+
O idioma a ser definido (ex.: "pt_BR", "en_US").
|
178
|
+
|
179
|
+
> **Nota:** Definir o idioma no elemento `<html>` é essencial para garantir que o conteúdo
|
180
|
+
da página seja interpretado corretamente por navegadores, leitores de tela e mecanismos de
|
181
|
+
busca, melhorando a acessibilidade e a indexação.
|
182
|
+
|
124
183
|
#### Returns
|
125
184
|
|
126
185
|
`void`
|
127
186
|
|
187
|
+
#### Example
|
188
|
+
|
189
|
+
```ts
|
190
|
+
LangUtils.setHtmlLanguage("en_US"); // Define o idioma como "en_US"
|
191
|
+
```
|
192
|
+
|
128
193
|
#### Source
|
129
194
|
|
130
|
-
src/utils/LangUtils.ts:
|
195
|
+
src/utils/LangUtils.ts:99
|