Skip to content

i18n

Your schema is defined, the base i18n is already working — action buttons, table UI, dialogs, and validation messages are all translated. Now it's time to add labels for the fields and groups you just created.

Domain Translations

Create a locale file with labels matching your schema's field names and group names:

typescript
// src/settings/locales/pt-BR.ts
export const ptBR = {
  product: {
    title: 'Product',
    fields: {
      id: 'ID',
      name: 'Name',
      sku: 'SKU',
      email: 'Email',
      active: 'Active',
      quantity: 'Quantity',
      price: 'Price',
    },
    groups: {
      info: 'Information',
      pricing: 'Pricing',
    },
  },
}

Each key maps directly to what you defined in the schema — name here is the name: text() field, info is the info: group() group.

Updating i18n.ts

In the Installation step you created i18n.ts with just the base translations. Now update it to merge your domain translations:

typescript
// src/settings/i18n.ts
import { ptBR } from '@anhanga/core'
import { configureI18n } from '@anhanga/react-native'
import { ptBR as local } from './locales/pt-BR'

export default configureI18n({
  resources: {
    'pt-BR': { translation: { ...ptBR, ...local } },
  },
  default: 'pt-BR',
  fallback: 'pt-BR',
})

The spread { ...ptBR, ...local } keeps all base keys and adds your domain-specific ones on top.

What the Base Provides

The ptBR export from @anhanga/core includes two namespaces:

common.* — UI chrome shared across all domains:

KeyExample
common.actions.add"Adicionar"
common.actions.create"Criar"
common.actions.create.success"Registro criado com sucesso"
common.actions.destroy.confirm"Deseja realmente excluir este registro?"
common.table.empty"Nenhum registro encontrado"
common.table.page"Página de "
common.dialog.confirm"Confirmar"
common.scopes.index"Listagem"

validation.* — validation error messages:

KeyExample
validation.required"Campo obrigatório"
validation.minLength"Mínimo de caracteres"
validation.min"Valor mínimo é "
validation.pattern"Formato inválido"

You don't need to write any of these — they come ready with @anhanga/core.

Key Conventions

Anhanga resolves labels automatically using this convention:

PatternResolves toExample
{domain}.titlePage titleproduct.title → "Product"
{domain}.fields.{field}Field labelproduct.fields.name → "Name"
{domain}.fields.{field}[{state}]Field label for a stateproduct.fields.email[error] → "Invalid email"
{domain}.groups.{group}Group titleproduct.groups.info → "Information"
common.actions.{action}Action button labelcommon.actions.add → "Adicionar"
common.scopes.{scope}Scope name (used in page titles)common.scopes.add → "Cadastro"

You never hardcode labels in your schema — define the fields and groups, then create the matching translation keys.

Next Steps

  • Screens — build the 4 CRUD screens

Released under the MIT License.