@sankhyalabs/core 6.2.0-rc.1 → 6.2.0
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/.docs/classes/LangUtils.md +195 -0
- package/.docs/globals.md +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/LangUtils.d.ts +83 -0
- package/dist/utils/LangUtils.js +121 -0
- package/dist/utils/LangUtils.js.map +1 -0
- package/package.json +2 -2
- package/reports/test-report.xml +590 -574
- package/src/index.ts +2 -1
- package/src/utils/LangUtils.ts +129 -0
- package/test/util/LangUtils.spec.ts +117 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
[**@sankhyalabs/core**](../README.md) • **Docs**
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@sankhyalabs/core](../globals.md) / LangUtils
|
|
6
|
+
|
|
7
|
+
# Class: LangUtils
|
|
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
|
+
|
|
12
|
+
## Constructors
|
|
13
|
+
|
|
14
|
+
### new LangUtils()
|
|
15
|
+
|
|
16
|
+
> **new LangUtils**(): [`LangUtils`](LangUtils.md)
|
|
17
|
+
|
|
18
|
+
#### Returns
|
|
19
|
+
|
|
20
|
+
[`LangUtils`](LangUtils.md)
|
|
21
|
+
|
|
22
|
+
## Properties
|
|
23
|
+
|
|
24
|
+
### ELanguages
|
|
25
|
+
|
|
26
|
+
> `static` **ELanguages**: *typeof* `__class`
|
|
27
|
+
|
|
28
|
+
Classe estática contendo os códigos de idioma predefinidos.
|
|
29
|
+
|
|
30
|
+
#### Source
|
|
31
|
+
|
|
32
|
+
src/utils/LangUtils.ts:14
|
|
33
|
+
|
|
34
|
+
## Methods
|
|
35
|
+
|
|
36
|
+
### applyLanguageFromCookie()
|
|
37
|
+
|
|
38
|
+
> `static` **applyLanguageFromCookie**(): `void`
|
|
39
|
+
|
|
40
|
+
Define o atributo `lang` no elemento `<html>` com base no cookie de idioma, se existir.
|
|
41
|
+
|
|
42
|
+
#### Returns
|
|
43
|
+
|
|
44
|
+
`void`
|
|
45
|
+
|
|
46
|
+
#### Example
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
LangUtils.applyLanguageFromCookie(); // Aplica o idioma do cookie ao elemento `<html>`
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### Source
|
|
53
|
+
|
|
54
|
+
src/utils/LangUtils.ts:123
|
|
55
|
+
|
|
56
|
+
***
|
|
57
|
+
|
|
58
|
+
### convertLanguage()
|
|
59
|
+
|
|
60
|
+
> `static` `private` **convertLanguage**(`lang`): `string`
|
|
61
|
+
|
|
62
|
+
Converte o idioma fornecido para um dos códigos predefinidos.
|
|
63
|
+
|
|
64
|
+
#### Parameters
|
|
65
|
+
|
|
66
|
+
• **lang**: `string`
|
|
67
|
+
|
|
68
|
+
O idioma a ser convertido (ex.: "en", "es", "pt-BR").
|
|
69
|
+
|
|
70
|
+
#### Returns
|
|
71
|
+
|
|
72
|
+
`string`
|
|
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
|
+
|
|
83
|
+
#### Source
|
|
84
|
+
|
|
85
|
+
src/utils/LangUtils.ts:30
|
|
86
|
+
|
|
87
|
+
***
|
|
88
|
+
|
|
89
|
+
### getHtmlLanguage()
|
|
90
|
+
|
|
91
|
+
> `static` **getHtmlLanguage**(): `string`
|
|
92
|
+
|
|
93
|
+
Recupera 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.
|
|
96
|
+
|
|
97
|
+
#### Returns
|
|
98
|
+
|
|
99
|
+
`string`
|
|
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
|
+
|
|
109
|
+
#### Source
|
|
110
|
+
|
|
111
|
+
src/utils/LangUtils.ts:77
|
|
112
|
+
|
|
113
|
+
***
|
|
114
|
+
|
|
115
|
+
### getLanguage()
|
|
116
|
+
|
|
117
|
+
> `static` **getLanguage**(): `string`
|
|
118
|
+
|
|
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"`.
|
|
124
|
+
|
|
125
|
+
#### Returns
|
|
126
|
+
|
|
127
|
+
`string`
|
|
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
|
+
|
|
137
|
+
#### Source
|
|
138
|
+
|
|
139
|
+
src/utils/LangUtils.ts:57
|
|
140
|
+
|
|
141
|
+
***
|
|
142
|
+
|
|
143
|
+
### getLanguageFromCookie()
|
|
144
|
+
|
|
145
|
+
> `static` **getLanguageFromCookie**(): `null` \| `string`
|
|
146
|
+
|
|
147
|
+
Recupera o valor do cookie de idioma.
|
|
148
|
+
|
|
149
|
+
#### Returns
|
|
150
|
+
|
|
151
|
+
`null` \| `string`
|
|
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
|
+
|
|
161
|
+
#### Source
|
|
162
|
+
|
|
163
|
+
src/utils/LangUtils.ts:112
|
|
164
|
+
|
|
165
|
+
***
|
|
166
|
+
|
|
167
|
+
### setHtmlLanguage()
|
|
168
|
+
|
|
169
|
+
> `static` **setHtmlLanguage**(`language`): `void`
|
|
170
|
+
|
|
171
|
+
Define o atributo `lang` no elemento `<html>` e atualiza o cookie de idioma.
|
|
172
|
+
|
|
173
|
+
#### Parameters
|
|
174
|
+
|
|
175
|
+
• **language**: `string`
|
|
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
|
+
|
|
183
|
+
#### Returns
|
|
184
|
+
|
|
185
|
+
`void`
|
|
186
|
+
|
|
187
|
+
#### Example
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
LangUtils.setHtmlLanguage("en_US"); // Define o idioma como "en_US"
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
#### Source
|
|
194
|
+
|
|
195
|
+
src/utils/LangUtils.ts:99
|
package/.docs/globals.md
CHANGED
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
- [IDBRepository](classes/IDBRepository.md)
|
|
47
47
|
- [JSUtils](classes/JSUtils.md)
|
|
48
48
|
- [KeyboardManager](classes/KeyboardManager.md)
|
|
49
|
+
- [LangUtils](classes/LangUtils.md)
|
|
49
50
|
- [LockManager](classes/LockManager.md)
|
|
50
51
|
- [MaskFormatter](classes/MaskFormatter.md)
|
|
51
52
|
- [NumberUtils](classes/NumberUtils.md)
|
package/dist/index.d.ts
CHANGED
|
@@ -53,4 +53,5 @@ import { DataUnitLoaderUtils, PaginationInfoBuilderParams } from "./dataunit/loa
|
|
|
53
53
|
import { ColumnFilterManager } from "./utils/ColumnFilterManager.js";
|
|
54
54
|
import { DataUnitInMemoryLoaderConfig, RECORD_DATE_FORMAT } from "./dataunit/loader/DataUnitInMemoryLoaderConfig.js";
|
|
55
55
|
import Base64Utils from "./utils/Base64Utils.js";
|
|
56
|
-
|
|
56
|
+
import { LangUtils } from './utils/LangUtils.js';
|
|
57
|
+
export { LockManager, LockManagerOperation, StringUtils, MaskFormatter, NumberUtils, FloatingManager, DateUtils, ArrayUtils, TimeFormatter, SkwHttpProvider, HttpProvider, RequestMetadata, AuthorizedServiceCaller, DataUnit, DataUnitStorage, Record, SavedRecord, DataType, UnitMetadata, FieldDescriptor, UserInterface, DependencyType, ChildDescriptor, ChildLink, DataUnitAction, Action, Change, Sort, Filter, ChangeOperation, DUActionInterceptor, ApplicationContext, WaitingChange, PageRequest, QuickFilter, ReadyUtil, ObjectUtils, WarningException, WaitingChangeException, ErrorException, ErrorTracking, ExecutionContext, PaginationInfo, SortingProvider, SortMode, LoadDataRequest, LoadDataResponse, SelectionInfo, SelectionMode, ElementIDUtils, IElementIDInfo, UserAgentUtils, JSUtils, VersionUtils, OnboardingUtils, PromiseSync, PromiseSyncCallback, HTMLBuilder, IRepository, IDBRepository, ILoadResult, IRepositoryIndex, FieldComparator, defaultDataLoader, KeyboardManager, SearchUtils, ServiceUtils, StorageType, OverflowWatcher, OnOverflowCallBack, OverflowDirection, OverFlowWatcherParams, OVERFLOWED_CLASS_NAME, DataUnitEventOptions, ServiceCanceledException, SilentException, DataUnitInMemoryLoader, DataUnitLoaderUtils, PaginationInfoBuilderParams, ColumnFilterManager, DataUnitInMemoryLoaderConfig, RECORD_DATE_FORMAT, Base64Utils, LangUtils, };
|
package/dist/index.js
CHANGED
|
@@ -47,6 +47,7 @@ import { DataUnitLoaderUtils } from "./dataunit/loader/utils/dataUnitLoaderUtils
|
|
|
47
47
|
import { ColumnFilterManager } from "./utils/ColumnFilterManager.js";
|
|
48
48
|
import { RECORD_DATE_FORMAT } from "./dataunit/loader/DataUnitInMemoryLoaderConfig.js";
|
|
49
49
|
import Base64Utils from "./utils/Base64Utils.js";
|
|
50
|
+
import { LangUtils } from './utils/LangUtils.js';
|
|
50
51
|
/*Classes públicas no pacote*/
|
|
51
|
-
export { LockManager, LockManagerOperation, StringUtils, MaskFormatter, NumberUtils, FloatingManager, DateUtils, ArrayUtils, TimeFormatter, SkwHttpProvider, HttpProvider, RequestMetadata, AuthorizedServiceCaller, DataUnit, DataUnitStorage, DataType, UserInterface, DependencyType, DataUnitAction, Action, Change, ChangeOperation, ApplicationContext, ReadyUtil, ObjectUtils, WarningException, WaitingChangeException, ErrorException, ErrorTracking, SortMode, SelectionInfo, SelectionMode, ElementIDUtils, UserAgentUtils, JSUtils, VersionUtils, OnboardingUtils, PromiseSync, HTMLBuilder, IDBRepository, FieldComparator, defaultDataLoader, KeyboardManager, SearchUtils, ServiceUtils, StorageType, OverflowWatcher, OverflowDirection, OVERFLOWED_CLASS_NAME, ServiceCanceledException, SilentException, DataUnitInMemoryLoader, DataUnitLoaderUtils, ColumnFilterManager, RECORD_DATE_FORMAT, Base64Utils, };
|
|
52
|
+
export { LockManager, LockManagerOperation, StringUtils, MaskFormatter, NumberUtils, FloatingManager, DateUtils, ArrayUtils, TimeFormatter, SkwHttpProvider, HttpProvider, RequestMetadata, AuthorizedServiceCaller, DataUnit, DataUnitStorage, DataType, UserInterface, DependencyType, DataUnitAction, Action, Change, ChangeOperation, ApplicationContext, ReadyUtil, ObjectUtils, WarningException, WaitingChangeException, ErrorException, ErrorTracking, SortMode, SelectionInfo, SelectionMode, ElementIDUtils, UserAgentUtils, JSUtils, VersionUtils, OnboardingUtils, PromiseSync, HTMLBuilder, IDBRepository, FieldComparator, defaultDataLoader, KeyboardManager, SearchUtils, ServiceUtils, StorageType, OverflowWatcher, OverflowDirection, OVERFLOWED_CLASS_NAME, ServiceCanceledException, SilentException, DataUnitInMemoryLoader, DataUnitLoaderUtils, ColumnFilterManager, RECORD_DATE_FORMAT, Base64Utils, LangUtils, };
|
|
52
53
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,eAAe,MAAM,yBAAyB,CAAC;AACtD,OAAO,SAAS,MAAM,sBAAsB,CAAC;AAC7C,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,QAAQ,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAsB,eAAe,EAAgE,aAAa,EAAuB,MAAM,mCAAmC,CAAC;AAC1L,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAiC,aAAa,EAAQ,QAAQ,EA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AmB,EAEnB,kBAAkB,EAClB,WAAW,EACX,SAAS,GACZ,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A classe `LangUtils` fornece métodos utilitários para gerenciar configurações de
|
|
3
|
+
* idioma, incluindo recuperar, definir e aplicar preferências de idioma.
|
|
4
|
+
*/
|
|
5
|
+
export declare class LangUtils {
|
|
6
|
+
/**
|
|
7
|
+
* Classe estática contendo os códigos de idioma predefinidos.
|
|
8
|
+
*
|
|
9
|
+
* @property PT_BR - Português (Brasil)
|
|
10
|
+
* @property EN_US - Inglês (Estados Unidos)
|
|
11
|
+
* @property ES_ES - Espanhol (Espanha)
|
|
12
|
+
*/
|
|
13
|
+
static ELanguages: {
|
|
14
|
+
new (): {};
|
|
15
|
+
PT_BR: string;
|
|
16
|
+
EN_US: string;
|
|
17
|
+
ES_ES: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Converte o idioma fornecido para um dos códigos predefinidos.
|
|
21
|
+
*
|
|
22
|
+
* @param lang - O idioma a ser convertido (ex.: "en", "es", "pt-BR").
|
|
23
|
+
* @returns O código de idioma correspondente (ex.: "en_US", "es_ES").
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* LangUtils.convertLanguage("en"); // Retorna "en_US"
|
|
27
|
+
* LangUtils.convertLanguage("es-es"); // Retorna "es_ES"
|
|
28
|
+
*/
|
|
29
|
+
private static convertLanguage;
|
|
30
|
+
/**
|
|
31
|
+
* Captura o idioma atualmente definido. Primeiro verifica se há um idioma
|
|
32
|
+
* armazenado nos cookies. Caso contrário, utiliza o idioma definido no elemento
|
|
33
|
+
* `<html>`. Se nenhum valor for encontrado nos cookies ou no elemento `<html>`,
|
|
34
|
+
* é utilizada a configuração do navegador. Caso o navegador também não forneça
|
|
35
|
+
* um idioma, o padrão será `"pt_BR"`.
|
|
36
|
+
*
|
|
37
|
+
* @returns O idioma definido (ex.: "pt_BR", "en_US").
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* LangUtils.getLanguage(); // Retorna o idioma atual
|
|
41
|
+
*/
|
|
42
|
+
static getLanguage(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Recupera o valor do atributo `lang` do elemento `<html>`. Se o ambiente
|
|
45
|
+
* estiver em modo de desenvolvimento, o idioma padrão será `"pt_BR"`. Caso
|
|
46
|
+
* contrário, utiliza o idioma do navegador ou `"pt-BR"` como padrão.
|
|
47
|
+
*
|
|
48
|
+
* @returns O idioma definido no elemento `<html>` ou o padrão.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* LangUtils.getHtmlLanguage(); // Retorna "pt_BR" no modo desenvolvimento
|
|
52
|
+
*/
|
|
53
|
+
static getHtmlLanguage(): string;
|
|
54
|
+
/**
|
|
55
|
+
* Define o atributo `lang` no elemento `<html>` e atualiza o cookie de idioma.
|
|
56
|
+
*
|
|
57
|
+
* @param language - O idioma a ser definido (ex.: "pt_BR", "en_US").
|
|
58
|
+
*
|
|
59
|
+
* > **Nota:** Definir o idioma no elemento `<html>` é essencial para garantir que o conteúdo
|
|
60
|
+
* da página seja interpretado corretamente por navegadores, leitores de tela e mecanismos de
|
|
61
|
+
* busca, melhorando a acessibilidade e a indexação.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* LangUtils.setHtmlLanguage("en_US"); // Define o idioma como "en_US"
|
|
65
|
+
*/
|
|
66
|
+
static setHtmlLanguage(language: string): void;
|
|
67
|
+
/**
|
|
68
|
+
* Recupera o valor do cookie de idioma.
|
|
69
|
+
*
|
|
70
|
+
* @returns O valor do cookie de idioma ou `null` se não existir.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* LangUtils.getLanguageFromCookie(); // Retorna "pt_BR" se o cookie existir
|
|
74
|
+
*/
|
|
75
|
+
static getLanguageFromCookie(): string | null;
|
|
76
|
+
/**
|
|
77
|
+
* Define o atributo `lang` no elemento `<html>` com base no cookie de idioma, se existir.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* LangUtils.applyLanguageFromCookie(); // Aplica o idioma do cookie ao elemento `<html>`
|
|
81
|
+
*/
|
|
82
|
+
static applyLanguageFromCookie(): void;
|
|
83
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
/**
|
|
3
|
+
* A classe `LangUtils` fornece métodos utilitários para gerenciar configurações de
|
|
4
|
+
* idioma, incluindo recuperar, definir e aplicar preferências de idioma.
|
|
5
|
+
*/
|
|
6
|
+
export class LangUtils {
|
|
7
|
+
/**
|
|
8
|
+
* Converte o idioma fornecido para um dos códigos predefinidos.
|
|
9
|
+
*
|
|
10
|
+
* @param lang - O idioma a ser convertido (ex.: "en", "es", "pt-BR").
|
|
11
|
+
* @returns O código de idioma correspondente (ex.: "en_US", "es_ES").
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* LangUtils.convertLanguage("en"); // Retorna "en_US"
|
|
15
|
+
* LangUtils.convertLanguage("es-es"); // Retorna "es_ES"
|
|
16
|
+
*/
|
|
17
|
+
static convertLanguage(lang) {
|
|
18
|
+
switch (lang.toLocaleLowerCase()) {
|
|
19
|
+
case "en":
|
|
20
|
+
case "en_us":
|
|
21
|
+
case "en-us":
|
|
22
|
+
return LangUtils.ELanguages.EN_US;
|
|
23
|
+
case "es":
|
|
24
|
+
case "es_es":
|
|
25
|
+
case "es-es":
|
|
26
|
+
return LangUtils.ELanguages.ES_ES;
|
|
27
|
+
default:
|
|
28
|
+
return LangUtils.ELanguages.PT_BR;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Captura o idioma atualmente definido. Primeiro verifica se há um idioma
|
|
33
|
+
* armazenado nos cookies. Caso contrário, utiliza o idioma definido no elemento
|
|
34
|
+
* `<html>`. Se nenhum valor for encontrado nos cookies ou no elemento `<html>`,
|
|
35
|
+
* é utilizada a configuração do navegador. Caso o navegador também não forneça
|
|
36
|
+
* um idioma, o padrão será `"pt_BR"`.
|
|
37
|
+
*
|
|
38
|
+
* @returns O idioma definido (ex.: "pt_BR", "en_US").
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* LangUtils.getLanguage(); // Retorna o idioma atual
|
|
42
|
+
*/
|
|
43
|
+
static getLanguage() {
|
|
44
|
+
const cookieLanguage = this.getLanguageFromCookie();
|
|
45
|
+
if (cookieLanguage) {
|
|
46
|
+
return this.convertLanguage(cookieLanguage);
|
|
47
|
+
}
|
|
48
|
+
return this.getHtmlLanguage();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Recupera o valor do atributo `lang` do elemento `<html>`. Se o ambiente
|
|
52
|
+
* estiver em modo de desenvolvimento, o idioma padrão será `"pt_BR"`. Caso
|
|
53
|
+
* contrário, utiliza o idioma do navegador ou `"pt-BR"` como padrão.
|
|
54
|
+
*
|
|
55
|
+
* @returns O idioma definido no elemento `<html>` ou o padrão.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* LangUtils.getHtmlLanguage(); // Retorna "pt_BR" no modo desenvolvimento
|
|
59
|
+
*/
|
|
60
|
+
static getHtmlLanguage() {
|
|
61
|
+
if (process.env.NODE_ENV === 'development') {
|
|
62
|
+
return LangUtils.ELanguages.PT_BR;
|
|
63
|
+
}
|
|
64
|
+
const lang = document.documentElement.lang || navigator.language || "pt-BR";
|
|
65
|
+
return this.convertLanguage(lang);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Define o atributo `lang` no elemento `<html>` e atualiza o cookie de idioma.
|
|
69
|
+
*
|
|
70
|
+
* @param language - O idioma a ser definido (ex.: "pt_BR", "en_US").
|
|
71
|
+
*
|
|
72
|
+
* > **Nota:** Definir o idioma no elemento `<html>` é essencial para garantir que o conteúdo
|
|
73
|
+
* da página seja interpretado corretamente por navegadores, leitores de tela e mecanismos de
|
|
74
|
+
* busca, melhorando a acessibilidade e a indexação.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* LangUtils.setHtmlLanguage("en_US"); // Define o idioma como "en_US"
|
|
78
|
+
*/
|
|
79
|
+
static setHtmlLanguage(language) {
|
|
80
|
+
document.documentElement.lang = language;
|
|
81
|
+
document.cookie = `lang=${language}; path=/;`;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Recupera o valor do cookie de idioma.
|
|
85
|
+
*
|
|
86
|
+
* @returns O valor do cookie de idioma ou `null` se não existir.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* LangUtils.getLanguageFromCookie(); // Retorna "pt_BR" se o cookie existir
|
|
90
|
+
*/
|
|
91
|
+
static getLanguageFromCookie() {
|
|
92
|
+
const match = document.cookie.match(new RegExp('(^| )lang=([^;]+)'));
|
|
93
|
+
return match ? match[2] : null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Define o atributo `lang` no elemento `<html>` com base no cookie de idioma, se existir.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* LangUtils.applyLanguageFromCookie(); // Aplica o idioma do cookie ao elemento `<html>`
|
|
100
|
+
*/
|
|
101
|
+
static applyLanguageFromCookie() {
|
|
102
|
+
const langFromCookie = this.getLanguageFromCookie();
|
|
103
|
+
if (langFromCookie) {
|
|
104
|
+
this.setHtmlLanguage(langFromCookie);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Classe estática contendo os códigos de idioma predefinidos.
|
|
110
|
+
*
|
|
111
|
+
* @property PT_BR - Português (Brasil)
|
|
112
|
+
* @property EN_US - Inglês (Estados Unidos)
|
|
113
|
+
* @property ES_ES - Espanhol (Espanha)
|
|
114
|
+
*/
|
|
115
|
+
LangUtils.ELanguages = (_a = class {
|
|
116
|
+
},
|
|
117
|
+
_a.PT_BR = "pt_BR",
|
|
118
|
+
_a.EN_US = "en_US",
|
|
119
|
+
_a.ES_ES = "es_ES",
|
|
120
|
+
_a);
|
|
121
|
+
//# sourceMappingURL=LangUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LangUtils.js","sourceRoot":"","sources":["../../src/utils/LangUtils.ts"],"names":[],"mappings":";AACA;;;GAGG;AACH,MAAM,OAAO,SAAS;IAclB;;;;;;;;;OASG;IACK,MAAM,CAAC,eAAe,CAAC,IAAY;QACvC,QAAQ,IAAI,CAAC,iBAAiB,EAAE,EAAE;YAC9B,KAAK,IAAI,CAAC;YACV,KAAK,OAAO,CAAC;YACb,KAAK,OAAO;gBACR,OAAO,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC;YACtC,KAAK,IAAI,CAAC;YACV,KAAK,OAAO,CAAC;YACb,KAAK,OAAO;gBACR,OAAO,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC;YACtC;gBACI,OAAO,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC;SACzC;IACL,CAAC;IAED;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,WAAW;QACrB,MAAM,cAAc,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAEpD,IAAI,cAAc,EAAE;YAChB,OAAO,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;SAC/C;QAED,OAAO,IAAI,CAAC,eAAe,EAAE,CAAC;IAClC,CAAC;IAED;;;;;;;;;OASG;IACI,MAAM,CAAC,eAAe;QACzB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE;YACxC,OAAO,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC;SACrC;QAED,MAAM,IAAI,GAAG,QAAQ,CAAC,eAAe,CAAC,IAAI,IAAI,SAAS,CAAC,QAAQ,IAAI,OAAO,CAAC;QAE5E,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,eAAe,CAAC,QAAgB;QAC1C,QAAQ,CAAC,eAAe,CAAC,IAAI,GAAG,QAAQ,CAAC;QACzC,QAAQ,CAAC,MAAM,GAAG,QAAQ,QAAQ,WAAW,CAAC;IAClD,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,qBAAqB;QAC/B,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC;QACrE,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,uBAAuB;QACjC,MAAM,cAAc,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAC;QACpD,IAAI,cAAc,EAAE;YAChB,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;SACxC;IACL,CAAC;;AAzHD;;;;;;GAMG;AACW,oBAAU,SAAG;KAI1B;IAHU,QAAK,GAAG,OAAQ;IAChB,QAAK,GAAG,OAAQ;IAChB,QAAK,GAAG,OAAQ;QACzB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sankhyalabs/core",
|
|
3
|
-
"version": "6.2.0
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"description": "Modulo core JavaScript da Sankhya.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"build": "tsc",
|
|
11
11
|
"build:watch": "tsc --watch",
|
|
12
12
|
"compile": "tsc",
|
|
13
|
-
"test": "jest --coverage --silent --testResultsProcessor jest-sonar-reporter",
|
|
13
|
+
"test": "jest --maxWorkers=1 --coverage --silent --testResultsProcessor jest-sonar-reporter",
|
|
14
14
|
"test.watch": "jest --coverage --watchAll",
|
|
15
15
|
"coverage": "jest --coverage",
|
|
16
16
|
"serve": "es-dev-server --node-resolve --watch",
|