forlogic-core 1.11.0 → 1.11.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/README.md +144 -0
- package/dist/README.md +144 -0
- package/dist/assets/index-4tvhvbTl.js +11591 -0
- package/dist/assets/index-Boj7SL5B.css +6 -0
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.esm.js +2 -2
- package/dist/index.html +30 -0
- package/dist/index.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -508,6 +508,150 @@ VITE_IS_QUALIEX=true
|
|
|
508
508
|
|
|
509
509
|
---
|
|
510
510
|
|
|
511
|
+
## 🌐 Setup de Traduções para Projetos Consumidores
|
|
512
|
+
|
|
513
|
+
O sistema de internacionalização (i18n) do `forlogic-core` carrega traduções dinamicamente do banco de dados Supabase. Para que funcione corretamente em projetos consumidores, siga os passos abaixo.
|
|
514
|
+
|
|
515
|
+
### Requisitos
|
|
516
|
+
|
|
517
|
+
| Requisito | Descrição |
|
|
518
|
+
|-----------|-----------|
|
|
519
|
+
| `VITE_SUPABASE_URL` | URL do projeto Supabase (mesma instância que contém `common.translations`) |
|
|
520
|
+
| `VITE_SUPABASE_PUBLISHABLE_KEY` | Chave pública (anon key) do Supabase |
|
|
521
|
+
| `i18next` | Peer dependency instalada |
|
|
522
|
+
| `react-i18next` | Peer dependency instalada |
|
|
523
|
+
| Tabela `common.translations` | Deve existir no Supabase com RLS pública para SELECT |
|
|
524
|
+
|
|
525
|
+
### Passo 1: Instalar Peer Dependencies
|
|
526
|
+
|
|
527
|
+
```bash
|
|
528
|
+
npm install i18next@^25.0.0 react-i18next@^16.0.0
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
### Passo 2: Configurar Variáveis de Ambiente
|
|
532
|
+
|
|
533
|
+
No arquivo `.env` do projeto consumidor:
|
|
534
|
+
|
|
535
|
+
```env
|
|
536
|
+
# Deve apontar para a mesma instância Supabase que contém common.translations
|
|
537
|
+
VITE_SUPABASE_URL=https://seu-projeto.supabase.co
|
|
538
|
+
VITE_SUPABASE_PUBLISHABLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
### Passo 3: Aguardar i18n Inicializar no main.tsx
|
|
542
|
+
|
|
543
|
+
**⚠️ CRÍTICO**: O `main.tsx` deve aguardar o i18n carregar as traduções antes de renderizar a aplicação.
|
|
544
|
+
|
|
545
|
+
```tsx
|
|
546
|
+
// src/main.tsx
|
|
547
|
+
import { createRoot } from 'react-dom/client';
|
|
548
|
+
import { i18n } from 'forlogic-core';
|
|
549
|
+
import App from './App';
|
|
550
|
+
import './index.css';
|
|
551
|
+
|
|
552
|
+
const renderApp = () => {
|
|
553
|
+
createRoot(document.getElementById("root")!).render(<App />);
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
// ✅ Aguardar i18n inicializar antes de renderizar
|
|
557
|
+
if (i18n.isInitialized) {
|
|
558
|
+
renderApp();
|
|
559
|
+
} else {
|
|
560
|
+
i18n.on('initialized', renderApp);
|
|
561
|
+
}
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
**❌ ERRADO** - Renderizar sem aguardar (mostrará apenas chaves):
|
|
565
|
+
|
|
566
|
+
```tsx
|
|
567
|
+
// ❌ NÃO FAÇA ISSO - traduções não estarão prontas
|
|
568
|
+
createRoot(document.getElementById("root")!).render(<App />);
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
### Passo 4: Usar CoreProviders no App.tsx
|
|
572
|
+
|
|
573
|
+
```tsx
|
|
574
|
+
// src/App.tsx
|
|
575
|
+
import { CoreProviders } from 'forlogic-core';
|
|
576
|
+
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
|
577
|
+
|
|
578
|
+
function App() {
|
|
579
|
+
return (
|
|
580
|
+
<CoreProviders>
|
|
581
|
+
<BrowserRouter>
|
|
582
|
+
<Routes>
|
|
583
|
+
{/* Suas rotas */}
|
|
584
|
+
</Routes>
|
|
585
|
+
</BrowserRouter>
|
|
586
|
+
</CoreProviders>
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
export default App;
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
### Passo 5: Usar useTranslation do forlogic-core
|
|
594
|
+
|
|
595
|
+
```tsx
|
|
596
|
+
// ❌ ERRADO - Cria instância separada
|
|
597
|
+
import { useTranslation } from 'react-i18next';
|
|
598
|
+
|
|
599
|
+
// ✅ CORRETO - Usa mesma instância configurada
|
|
600
|
+
import { useTranslation } from 'forlogic-core';
|
|
601
|
+
|
|
602
|
+
function MeuComponente() {
|
|
603
|
+
const { t } = useTranslation();
|
|
604
|
+
return <h1>{t('minha.chave')}</h1>;
|
|
605
|
+
}
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
### Troubleshooting
|
|
609
|
+
|
|
610
|
+
#### Traduções mostram apenas as chaves (ex: `common.save` ao invés de "Salvar")
|
|
611
|
+
|
|
612
|
+
| Causa | Solução |
|
|
613
|
+
|-------|---------|
|
|
614
|
+
| `main.tsx` não aguarda i18n | Adicionar verificação `i18n.isInitialized` conforme Passo 3 |
|
|
615
|
+
| Peer dependencies faltando | Instalar `i18next` e `react-i18next` |
|
|
616
|
+
| Variáveis de ambiente incorretas | Verificar `VITE_SUPABASE_URL` e `VITE_SUPABASE_PUBLISHABLE_KEY` |
|
|
617
|
+
| Supabase diferente | Verificar se aponta para a mesma instância com `common.translations` |
|
|
618
|
+
| Import de `react-i18next` direto | Usar import de `forlogic-core` |
|
|
619
|
+
|
|
620
|
+
#### Debug: Verificar se traduções foram carregadas
|
|
621
|
+
|
|
622
|
+
```tsx
|
|
623
|
+
import { i18n } from 'forlogic-core';
|
|
624
|
+
|
|
625
|
+
// No console
|
|
626
|
+
console.log('i18n initialized:', i18n.isInitialized);
|
|
627
|
+
console.log('Current language:', i18n.language);
|
|
628
|
+
console.log('Loaded resources:', i18n.store.data);
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
#### Habilitar modo debug
|
|
632
|
+
|
|
633
|
+
Adicione no `.env`:
|
|
634
|
+
|
|
635
|
+
```env
|
|
636
|
+
VITE_I18N_DEBUG_MODE=true
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
Com debug ativo, chaves traduzidas aparecem como `[chave ✅]` e chaves não encontradas como `[⚠️ chave]`.
|
|
640
|
+
|
|
641
|
+
### Checklist de Configuração
|
|
642
|
+
|
|
643
|
+
```markdown
|
|
644
|
+
- [ ] Instalou `i18next@^25.0.0` e `react-i18next@^16.0.0`?
|
|
645
|
+
- [ ] Configurou `VITE_SUPABASE_URL` apontando para a instância correta?
|
|
646
|
+
- [ ] Configurou `VITE_SUPABASE_PUBLISHABLE_KEY`?
|
|
647
|
+
- [ ] O `main.tsx` aguarda `i18n.isInitialized` antes de renderizar?
|
|
648
|
+
- [ ] O `App.tsx` usa `CoreProviders`?
|
|
649
|
+
- [ ] Todos os imports de `useTranslation` são de `forlogic-core`?
|
|
650
|
+
- [ ] A tabela `common.translations` existe e tem RLS pública para SELECT?
|
|
651
|
+
```
|
|
652
|
+
|
|
653
|
+
---
|
|
654
|
+
|
|
511
655
|
## 🚀 Quick Setup: CoreProviders
|
|
512
656
|
|
|
513
657
|
O `CoreProviders` é um componente que encapsula todos os providers essenciais da biblioteca, simplificando drasticamente a configuração de novos projetos.
|
package/dist/README.md
CHANGED
|
@@ -508,6 +508,150 @@ VITE_IS_QUALIEX=true
|
|
|
508
508
|
|
|
509
509
|
---
|
|
510
510
|
|
|
511
|
+
## 🌐 Setup de Traduções para Projetos Consumidores
|
|
512
|
+
|
|
513
|
+
O sistema de internacionalização (i18n) do `forlogic-core` carrega traduções dinamicamente do banco de dados Supabase. Para que funcione corretamente em projetos consumidores, siga os passos abaixo.
|
|
514
|
+
|
|
515
|
+
### Requisitos
|
|
516
|
+
|
|
517
|
+
| Requisito | Descrição |
|
|
518
|
+
|-----------|-----------|
|
|
519
|
+
| `VITE_SUPABASE_URL` | URL do projeto Supabase (mesma instância que contém `common.translations`) |
|
|
520
|
+
| `VITE_SUPABASE_PUBLISHABLE_KEY` | Chave pública (anon key) do Supabase |
|
|
521
|
+
| `i18next` | Peer dependency instalada |
|
|
522
|
+
| `react-i18next` | Peer dependency instalada |
|
|
523
|
+
| Tabela `common.translations` | Deve existir no Supabase com RLS pública para SELECT |
|
|
524
|
+
|
|
525
|
+
### Passo 1: Instalar Peer Dependencies
|
|
526
|
+
|
|
527
|
+
```bash
|
|
528
|
+
npm install i18next@^25.0.0 react-i18next@^16.0.0
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
### Passo 2: Configurar Variáveis de Ambiente
|
|
532
|
+
|
|
533
|
+
No arquivo `.env` do projeto consumidor:
|
|
534
|
+
|
|
535
|
+
```env
|
|
536
|
+
# Deve apontar para a mesma instância Supabase que contém common.translations
|
|
537
|
+
VITE_SUPABASE_URL=https://seu-projeto.supabase.co
|
|
538
|
+
VITE_SUPABASE_PUBLISHABLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
### Passo 3: Aguardar i18n Inicializar no main.tsx
|
|
542
|
+
|
|
543
|
+
**⚠️ CRÍTICO**: O `main.tsx` deve aguardar o i18n carregar as traduções antes de renderizar a aplicação.
|
|
544
|
+
|
|
545
|
+
```tsx
|
|
546
|
+
// src/main.tsx
|
|
547
|
+
import { createRoot } from 'react-dom/client';
|
|
548
|
+
import { i18n } from 'forlogic-core';
|
|
549
|
+
import App from './App';
|
|
550
|
+
import './index.css';
|
|
551
|
+
|
|
552
|
+
const renderApp = () => {
|
|
553
|
+
createRoot(document.getElementById("root")!).render(<App />);
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
// ✅ Aguardar i18n inicializar antes de renderizar
|
|
557
|
+
if (i18n.isInitialized) {
|
|
558
|
+
renderApp();
|
|
559
|
+
} else {
|
|
560
|
+
i18n.on('initialized', renderApp);
|
|
561
|
+
}
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
**❌ ERRADO** - Renderizar sem aguardar (mostrará apenas chaves):
|
|
565
|
+
|
|
566
|
+
```tsx
|
|
567
|
+
// ❌ NÃO FAÇA ISSO - traduções não estarão prontas
|
|
568
|
+
createRoot(document.getElementById("root")!).render(<App />);
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
### Passo 4: Usar CoreProviders no App.tsx
|
|
572
|
+
|
|
573
|
+
```tsx
|
|
574
|
+
// src/App.tsx
|
|
575
|
+
import { CoreProviders } from 'forlogic-core';
|
|
576
|
+
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
|
577
|
+
|
|
578
|
+
function App() {
|
|
579
|
+
return (
|
|
580
|
+
<CoreProviders>
|
|
581
|
+
<BrowserRouter>
|
|
582
|
+
<Routes>
|
|
583
|
+
{/* Suas rotas */}
|
|
584
|
+
</Routes>
|
|
585
|
+
</BrowserRouter>
|
|
586
|
+
</CoreProviders>
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
export default App;
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
### Passo 5: Usar useTranslation do forlogic-core
|
|
594
|
+
|
|
595
|
+
```tsx
|
|
596
|
+
// ❌ ERRADO - Cria instância separada
|
|
597
|
+
import { useTranslation } from 'react-i18next';
|
|
598
|
+
|
|
599
|
+
// ✅ CORRETO - Usa mesma instância configurada
|
|
600
|
+
import { useTranslation } from 'forlogic-core';
|
|
601
|
+
|
|
602
|
+
function MeuComponente() {
|
|
603
|
+
const { t } = useTranslation();
|
|
604
|
+
return <h1>{t('minha.chave')}</h1>;
|
|
605
|
+
}
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
### Troubleshooting
|
|
609
|
+
|
|
610
|
+
#### Traduções mostram apenas as chaves (ex: `common.save` ao invés de "Salvar")
|
|
611
|
+
|
|
612
|
+
| Causa | Solução |
|
|
613
|
+
|-------|---------|
|
|
614
|
+
| `main.tsx` não aguarda i18n | Adicionar verificação `i18n.isInitialized` conforme Passo 3 |
|
|
615
|
+
| Peer dependencies faltando | Instalar `i18next` e `react-i18next` |
|
|
616
|
+
| Variáveis de ambiente incorretas | Verificar `VITE_SUPABASE_URL` e `VITE_SUPABASE_PUBLISHABLE_KEY` |
|
|
617
|
+
| Supabase diferente | Verificar se aponta para a mesma instância com `common.translations` |
|
|
618
|
+
| Import de `react-i18next` direto | Usar import de `forlogic-core` |
|
|
619
|
+
|
|
620
|
+
#### Debug: Verificar se traduções foram carregadas
|
|
621
|
+
|
|
622
|
+
```tsx
|
|
623
|
+
import { i18n } from 'forlogic-core';
|
|
624
|
+
|
|
625
|
+
// No console
|
|
626
|
+
console.log('i18n initialized:', i18n.isInitialized);
|
|
627
|
+
console.log('Current language:', i18n.language);
|
|
628
|
+
console.log('Loaded resources:', i18n.store.data);
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
#### Habilitar modo debug
|
|
632
|
+
|
|
633
|
+
Adicione no `.env`:
|
|
634
|
+
|
|
635
|
+
```env
|
|
636
|
+
VITE_I18N_DEBUG_MODE=true
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
Com debug ativo, chaves traduzidas aparecem como `[chave ✅]` e chaves não encontradas como `[⚠️ chave]`.
|
|
640
|
+
|
|
641
|
+
### Checklist de Configuração
|
|
642
|
+
|
|
643
|
+
```markdown
|
|
644
|
+
- [ ] Instalou `i18next@^25.0.0` e `react-i18next@^16.0.0`?
|
|
645
|
+
- [ ] Configurou `VITE_SUPABASE_URL` apontando para a instância correta?
|
|
646
|
+
- [ ] Configurou `VITE_SUPABASE_PUBLISHABLE_KEY`?
|
|
647
|
+
- [ ] O `main.tsx` aguarda `i18n.isInitialized` antes de renderizar?
|
|
648
|
+
- [ ] O `App.tsx` usa `CoreProviders`?
|
|
649
|
+
- [ ] Todos os imports de `useTranslation` são de `forlogic-core`?
|
|
650
|
+
- [ ] A tabela `common.translations` existe e tem RLS pública para SELECT?
|
|
651
|
+
```
|
|
652
|
+
|
|
653
|
+
---
|
|
654
|
+
|
|
511
655
|
## 🚀 Quick Setup: CoreProviders
|
|
512
656
|
|
|
513
657
|
O `CoreProviders` é um componente que encapsula todos os providers essenciais da biblioteca, simplificando drasticamente a configuração de novos projetos.
|