VerifyKitv0.5.1

Internationalization (i18n)

VerifyKit includes a lightweight translation system for UI strings. You can switch locales, override specific strings, or register entirely new locales.


API Overview

The i18n module exports the following functions:

FunctionDescription
t(key, locale?)Translate a key. Falls back to English, then to the key itself.
setLocale(locale)Set the active locale globally.
getLocale()Get the current active locale code.
registerLocale(locale, strings)Register a new locale or add overrides to an existing one.
getAvailableLocales()Get an array of all registered locale codes.
typescript
import { t, setLocale, getLocale, registerLocale, getAvailableLocales } from '@trexolab/verifykit-react'

The following types are also exported:

typescript
import type { Locale, TranslationStrings } from '@trexolab/verifykit-react'

Locale is typed as 'en' | 'fr' | 'de' | 'es' | 'ar' | 'ja' | 'zh' | string, allowing both built-in and custom locale codes.


Default Locale

The default locale is 'en' (English). All built-in UI components use t() to resolve their display strings. If a key is not found in the current locale, the system falls back to the English translation, then to the raw key string.


Translation Keys

The TranslationStrings interface defines all translatable keys. Below is the complete list with their default English values.

Toolbar

KeyDefault (English)
toolbar.openFileOpen file
toolbar.previousPagePrevious page
toolbar.nextPageNext page
toolbar.zoomInZoom in
toolbar.zoomOutZoom out
toolbar.fitWidthFit width
toolbar.fitPageFit page
toolbar.rotateClockwiseRotate clockwise
toolbar.rotateCounterclockwiseRotate counterclockwise
toolbar.searchSearch
toolbar.printPrint
toolbar.downloadDownload
toolbar.themeToggle theme
toolbar.fullscreenFullscreen
toolbar.signaturesSignatures
toolbar.moreOptionsMore options

Status Messages

KeyDefault (English)
status.validValid
status.invalidInvalid
status.warningWarning
status.unknownUnknown
status.pendingPending

Signature Panel

KeyDefault (English)
panel.signaturesSignatures
panel.noSignaturesNo signatures found
panel.unsignedFieldsUnsigned signature fields
panel.signerCertificateSigner Certificate
panel.certificateChainCertificate Chain
panel.viewPropertiesView Properties

Document

KeyDefault (English)
document.propertiesDocument Properties
document.metadataMetadata

Find Bar

KeyDefault (English)
find.placeholderFind in document...
find.noResultsNo results found
find.matchCaseMatch case
find.wholeWordsWhole words

Welcome Screen

KeyDefault (English)
welcome.titleOpen a PDF document
welcome.subtitleDrag & drop a file here, or click to browse
welcome.dropHintDrop PDF file here

Password Dialog

KeyDefault (English)
password.titlePassword Required
password.placeholderEnter password
password.submitOpen
password.incorrectIncorrect password. Please try again.

Verification

KeyDefault (English)
verification.checkingVerifying signatures...
verification.completeVerification complete

PAdES Levels

KeyDefault (English)
pades.B-BPAdES B-B (Basic)
pades.B-TPAdES B-T (Timestamp)
pades.B-LTPAdES B-LT (Long-Term)
pades.B-LTAPAdES B-LTA (Long-Term Archival)

General

KeyDefault (English)
general.closeClose
general.cancelCancel
general.okOK
general.loadingLoading...
general.errorError

The TranslationStrings interface also includes an index signature ([key: string]: string), allowing you to add custom keys beyond those listed above.


Using with VerifyKitProvider

The VerifyKitProvider accepts locale and translations in its config:

tsx
<VerifyKitProvider config={{
  workerUrl: '/pdf.worker.min.mjs',
  locale: 'fr',
  translations: {
    'toolbar.search': 'Rechercher',
    'panel.noSignatures': 'Aucune signature trouvée',
  },
}}>
  <App />
</VerifyKitProvider>
  • locale sets the active locale when the provider mounts.
  • translations registers partial overrides for the specified locale. If locale is 'fr', the translations are merged into the 'fr' locale.

Switching Locale at Runtime

Use setLocale() to change the active locale. Components that call t() during render will pick up the new locale on the next render cycle.

typescript
import { setLocale, getLocale } from '@trexolab/verifykit-react'
 
// Check current locale
console.log(getLocale()) // 'en'
 
// Switch to French
setLocale('fr')
console.log(getLocale()) // 'fr'

Note: setLocale() changes a module-level variable. It does not trigger a React re-render on its own. If you need the UI to update immediately, trigger a re-render in your application (e.g., via state change).


Adding a Custom Locale

Use registerLocale() to add a complete locale or extend an existing one:

typescript
import { registerLocale, setLocale } from '@trexolab/verifykit-react'
 
// Register a full Portuguese locale
registerLocale('pt', {
  'toolbar.openFile': 'Abrir arquivo',
  'toolbar.previousPage': 'Pagina anterior',
  'toolbar.nextPage': 'Proxima pagina',
  'toolbar.zoomIn': 'Ampliar',
  'toolbar.zoomOut': 'Reduzir',
  'toolbar.search': 'Pesquisar',
  'toolbar.print': 'Imprimir',
  'toolbar.download': 'Baixar',
  'status.valid': 'Valido',
  'status.invalid': 'Invalido',
  'status.unknown': 'Desconhecido',
  'panel.signatures': 'Assinaturas',
  'panel.noSignatures': 'Nenhuma assinatura encontrada',
  'welcome.title': 'Abra um documento PDF',
  'welcome.subtitle': 'Arraste e solte um arquivo aqui, ou clique para navegar',
  'general.close': 'Fechar',
  'general.cancel': 'Cancelar',
  'general.ok': 'OK',
})
 
// Activate it
setLocale('pt')

Any keys not provided in your custom locale will fall back to the English default.


Overriding Specific Strings

You can override individual strings without creating a full locale. This is useful for branding or terminology adjustments:

typescript
import { registerLocale } from '@trexolab/verifykit-react'
 
// Override just a few English strings
registerLocale('en', {
  'welcome.title': 'Upload your document',
  'welcome.subtitle': 'Drop a signed PDF here to verify its signatures',
})

Calling registerLocale() on an existing locale merges the new strings with the existing ones. Existing strings that are not included in the override are preserved.


Listing Available Locales

typescript
import { getAvailableLocales } from '@trexolab/verifykit-react'
 
console.log(getAvailableLocales()) // ['en']
 
// After registering custom locales:
registerLocale('fr', { 'general.ok': 'OK' })
registerLocale('de', { 'general.ok': 'OK' })
console.log(getAvailableLocales()) // ['en', 'fr', 'de']

Using t() Directly

The t() function can be used outside of React components for headless or utility code:

typescript
import { t, setLocale } from '@trexolab/verifykit-react'
 
setLocale('en')
console.log(t('status.valid'))   // 'Valid'
console.log(t('status.invalid')) // 'Invalid'
 
// Override per-call without changing the global locale
console.log(t('status.valid', 'fr')) // Uses French if registered, else falls back to English

The fallback chain is:

  1. The requested locale's value for the key
  2. The English ('en') value for the key
  3. The raw key string itself