Skip to main content

Languages and strings

Three locales are bundled: en, pt-BR and es.

Choosing a locale​

<OfflineDetector locale="pt-BR">
<App />
</OfflineDetector>

On the web the locale prop decides, and en is used when it is not given. On native the locale prop wins, and without it the device locale is used. Anything unknown resolves to en. The resolver never throws:

import { resolveLocale } from '@rogeriodocarmo/offline-detector-web'; // or -native

resolveLocale('pt-PT'); // 'pt-BR'
resolveLocale('es-MX'); // 'es'
resolveLocale('fr'); // 'en'

Any pt variant gives pt-BR, any es-* gives es, and anything else gives en.

The strings​

Keyenpt-BRes
offlineNo internetSem internetSin internet
offlineNoInterfaceNo network connectionSem conexão com a redeSin conexión de red
offlineNoInternetConnected, but no internetConectado, mas sem internetConectado, pero sin internet
onlineBack onlineConexão restabelecidaConexión restablecida
retryRetryTentar novamenteReintentar
checkingChecking…Verificando…Verificando…
continueOfflineContinue offlineContinuar offlineContinuar sin conexión
dismissDismissFecharCerrar
dismissHintSwipe left or right to dismissDeslize para a esquerda ou direita para fecharDesliza a izquierda o a derecha para descartar
indicatorLabelOnlineOnlineOnlineEn línea
indicatorLabelOfflineNo internetSem internetSin internet
indicatorLabelCheckingChecking connectionVerificando conexãoVerificando conexión
indicatorAccessibleNameConnection status: {status}Status da conexão: {status}Estado de la conexión: {status}
fullScreenTitleNo internetSem internetSin internet
fullScreenBodyCheck your connection and try again.Verifique sua conexão e tente novamente.Revisa tu conexión e inténtalo de nuevo.
fullScreenRetryTry againTentar novamenteIntentar de nuevo

{status} is replaced with the matching indicatorLabel* string.

Overriding strings​

Pass a partial object. Each key you give wins over the locale's text; the rest stay.

<OfflineDetector locale="en" strings={{ offline: 'You are offline', retry: 'Try again' }}>
<App />
</OfflineDetector>

The same merge is available as a function. These helpers, and resolveLocale above, are exported by both @rogeriodocarmo/offline-detector-web and @rogeriodocarmo/offline-detector-native, so one package is enough to import them:

import {
resolveStrings,
offlineMessage,
indicatorName,
} from '@rogeriodocarmo/offline-detector-web'; // or -native

const strings = resolveStrings('pt-BR', { retry: 'Outra vez' });
offlineMessage(state, strings); // 'Sem internet' (always, by default)
offlineMessage(state, strings, true); // reason-aware: 'Sem conexão com a rede' or 'Conectado, mas sem internet'
indicatorName(strings, strings.indicatorLabelOffline); // 'Status da conexão: Sem internet'

An override set to undefined is ignored, and an empty string is kept. indicatorName treats the label as plain text.

Reason-aware messages​

By default every offline message is offline. With distinguishReason, the message becomes offlineNoInterface when the reason is no-interface and offlineNoInternet when it is no-internet. The full-screen body does not change. The full-screen title is fullScreenTitle, on web and native alike, unless distinguishReason is on: then it is the reason-aware message.

Adding a language​

The bundled tables cover three locales. For another language, pass a complete strings object, or the keys you need, together with the closest bundled locale.

About these docs​

These docs are available in the same three languages. The translations were written with care but still need a review by native speakers.