Introducing a new way to review your PRs.

Read the announcement

appwrite / sdk-for-react-native

[READ ONLY] Official Appwrite React Native SDK 💙 ⚛︎

View on GitHub

24 documents · Updated Nov 18, 2026

docs / locale-and-avatars

Locale and avatars

Locale and avatar services provide shared capabilities for apps that need regional context or ready-to-use image assets. Locale data supports location-aware interfaces and form choices. Avatar endpoints turn browser codes, country codes, payment card codes, user identity inputs, names, text, and remote URLs into image data or directly usable image URLs.

This page is a child of Realtime and utility services. The related Realtime subscriptions and presence page covers the live-update services that sit beside these request-based utilities.

Service boundary

The Locale service returns structured regional data, while the Avatars service returns generated image content. Both services use the shared client and project context, so callers can use them as independent utility services without managing a separate data store or asset pipeline.

The main service split is:

ServiceSystem purposeMain result
LocaleResolve the caller's regional context and provide standard locale catalogsTyped locale objects and lists
AvatarsCreate or fetch display-ready visual assetsImage bytes or an image URL

Request and asset flow

The following flow shows how an app moves from a locale or asset request to a typed result or image resource.

flowchart LR
    A[App request] --> B{Utility service}
    B -->|Regional context or catalog| C[Locale service]
    B -->|Visual asset| D[Avatars service]
    C --> E[Locale model or list]
    D --> F[Image bytes]
    D --> G[Image URL]

References: src/…/locale.ts• L6-51 src/…/avatars.ts• L15-18 src/…/avatars.ts• L1711-1751

Locale metadata

Locale metadata gives an app a common vocabulary for geography, language, money, and phone entry. The service separates caller-specific location data from reusable reference catalogs, which lets an app use detected context and controlled selection lists in the same flow.

Location context

The location request derives regional context from the caller's IP address. Its result includes country and continent identity, European Union membership, currency, and IP information. City, time zone, postal code, coordinates, and network details are optional, so a consumer must treat them as available context rather than guaranteed fields.

The response uses standard country and currency codes. Country and continent names can be localized through the request's supported locale setting, which keeps display text separate from stable codes.

References: src/…/locale.ts• L11-50 src/models.ts• L899-975

Reference catalogs

The catalog requests provide lists for values that are often needed before a user submits a form. Each list carries a total and an array of typed records, so the same response shape applies while the record fields differ by domain.

CatalogProduct useRecord information
Locale codesChoose supported language or locale labelsISO 639-1 code and name
ContinentsGroup or filter countriesName and two-letter code
CountriesBuild country selectors and regional filtersName and ISO 3166-1 alpha-2 code
European Union countriesLimit a selector to current EU membersCountry name and code
Country phone codesBuild phone country-code choicesPhone code with country identity
CurrenciesFormat prices and money inputCode, symbols, names, decimal digits, and rounding
LanguagesBuild language selectorsCode, English name, and native name

The service does not expose a separate time zone catalog. Time zone is an optional field in IP-derived locale context. For browser rendering, supported IANA time zone values are exposed as the Timezone value type and are passed to screenshot requests.

References: src/…/locale.ts• L53-621 src/models.ts• L145-230 src/models.ts• L1228-1323 src/…/timezone.ts• L1-421

Avatar assets

Avatar assets are generated or fetched at request time from a small input such as a code, user identity, name, text, or URL. The Avatars service supports binary retrieval for app-managed image handling and URL generation for consumers that can load an image resource directly.

Asset families

Each asset family solves a different display problem. Code-based assets use shared value types so a browser code, country code, or payment card code stays aligned with the SDK's supported values.

AssetInputDisplay purpose
Browser iconBrowser code from a user sessionShow the browser used by a user
Credit card iconCredit card provider codeShow a payment card provider
FlagISO 3166-1 alpha-2 country codeShow country identity
Initials avatarOptional nameProvide a fallback user image; the service can use the current user's name or email
Profile photoUser ID, hashed email, or nameResolve the best available profile image with fallbacks
QR imagePlain textShare a link or other encoded text as a scannable image
FaviconRemote website URLShow a site's favorite icon
ImageRemote image URLFetch and resize a remote image for display
ScreenshotWebsite URL and browser contextCapture a rendered page as an image

The small icon and initials families support width, height, and quality controls. The image family supports remote-image resizing. QR output supports size, margin, and an optional download response.

References: src/…/avatars.ts• L20-37 src/…/avatars.ts• L148-276 src/…/avatars.ts• L278-347 src/…/avatars.ts• L349-472 src/…/avatars.ts• L474-579 src/…/avatars.ts• L581-707 src/…/avatars.ts• L1212-1333 src/…/browser.ts• L1-16 src/…/credit-card.ts• L1-20 src/…/flag.ts• L1-197 src/client.ts• L273-279

Initials and remote assets

Initials avatars provide a user image when an uploaded profile image is not available. A supplied name takes priority. Without one, the service can use the signed-in user's name or email. If no identity is available, it returns an empty avatar. The generated background can be set by the caller, while the default theme stays stable for the same initials.

Remote assets depend on the target URL being usable by the service. Favicon and image retrieval do not follow HTTP redirects. This makes the supplied URL part of the asset contract rather than a hint that the service will discover another final URL.

References: src/…/avatars.ts• L278-347 src/…/avatars.ts• L474-579 src/…/avatars.ts• L581-707 src/…/avatars.ts• L1813-1961

Profile photo resolution

Profile photo resolution finds the first usable image for a user instead of requiring each app to build its own fallback chain. For an identified user, the service checks an uploaded photo and external avatar sources before initials and a built-in fallback. An explicit hashed email or name can replace only that input while the remaining user sources stay available.

When no user ID is supplied, the service resolves only from the given hashed email or name. It does not use the signed-in user's profile in that mode. Email input must be a SHA-256 hash of the lowercase, trimmed address, so the address itself is not placed in the request URL.

An uploaded photo takes priority over other sources. Deleting it stores the built-in placeholder as the user's selected photo until a new photo is uploaded. This means deletion is a persistent choice rather than a request to resume normal fallback resolution.

References: src/…/avatars.ts• L709-881 src/…/avatars.ts• L883-1210 src/…/avatars.ts• L2027-2112

Browser screenshots

Screenshot generation renders a website in a headless browser and captures either the visible viewport or the full page. The request can shape the rendered experience with browser headers, viewport size, scale, theme, user agent, locale, time zone, location, touch support, permissions, and a wait period before capture. Output size, quality, and image format then control the returned asset.

The screenshot controls form one relationship: browser context changes what the page renders, while output controls change how that rendered page is delivered. The exported BrowserTheme, Timezone, BrowserPermission, and ImageFormat values constrain the most important context and output choices.

References: src/…/avatars.ts• L1335-1386 src/…/avatars.ts• L1562-1689 src/…/avatars.ts• L2170-2325 src/…/browser-theme.ts• L1-4 src/…/browser-permission.ts• L1-22 src/…/image-format.ts• L1-9

Binary and URL access

Every generated avatar family has a request method that returns image bytes. The service also provides URL helpers for browser, credit card, favicon, flag, image, initials, profile photo, QR, and screenshot assets. This gives an app a choice between handling the response in native code or handing a constructed resource URL to an image view.

The URL form is useful when the consuming UI accepts a remote image source. The binary form is useful when the app must inspect, store, or transform the returned image before display.

References: src/…/avatars.ts• L20-145 src/…/avatars.ts• L148-276 src/…/avatars.ts• L278-579 src/…/avatars.ts• L581-881 src/…/avatars.ts• L1212-1333 src/…/avatars.ts• L1692-2325

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the locale service methods and the matching Models list or record shape aligned. A field rename can break catalog consumers without changing the request name.
  • Keep browser session codes and the Browser values aligned. Browser icons rely on codes produced by the account session flow.
  • Keep the binary avatar methods and their URL helpers aligned for each asset family. A change to one request's parameters can silently make the two access paths return different assets.
  • Keep screenshot context values aligned with the exported enums. Changes to theme, permissions, time zones, or image formats affect both request typing and rendered output.
  • Keep profile-photo source order and input rules aligned across binary and URL access. In particular, preserve the hashed-email contract and the distinction between a user-specific request and a value-only request.
  • Keep profile-photo upload and deletion semantics aligned with source precedence. A stored placeholder must continue to block lower-priority sources until a new upload replaces it.
  • Keep remote URL policy changes synchronized across favicon and image behavior. Redirect handling changes the meaning of the URL supplied by callers.
  • Keep the public exports in src/index.ts aligned with new locale or avatar value types. Consumers rely on that file as the package entry point.

Important failure modes

TriggerConsequenceGuard
A required browser code, credit card code, remote URL, QR text, or screenshot URL is missingThe client raises an AppwriteException before it can produce an assetTreat these inputs as required; keep the name optional only for initials avatars
A browser, credit card, or flag path code is . or ..The client rejects the path value before sending the requestUse the supported enum code values rather than path-like values
A favicon or image source needs an HTTP redirectThe remote asset request does not reach the redirected resourcePass the final usable URL when the source does not serve the asset directly
A raw email address is supplied as emailHashExternal avatar lookup receives a value that is not the required hash and the expected profile image may not resolveSend only the SHA-256 hash of the lowercase, trimmed email
A locale consumer assumes optional location fields always existMissing city, time zone, postal code, or network data causes empty or invalid UI valuesUse the required country, continent, and currency fields as the base and check optional fields before use
A screenshot uses an invalid context value or an incompatible location settingThe rendered page can differ from the intended browser state or the request can failUse exported theme, permission, time zone, and format values and keep location parameters within their supported ranges
An uploaded photo is deleted when the app expects normal fallback resolutionThe stored placeholder remains the user's selected photo and lower-priority sources stay hiddenTreat deletion as a persistent placeholder choice; upload a new photo to restore custom-photo priority
An image response is handled as JSONThe app cannot display the returned asset bytesUse the binary result as image data or use the matching URL helper

Key files

FileWhy to read it
src/…/locale.tsDefines the location request and the locale reference catalogs
src/models.tsDefines the locale context, catalog records, and list shapes returned to callers
src/…/avatars.tsDefines the asset families, profile-photo resolution, profile-photo lifecycle, screenshot context, binary results, and URL access paths
src/index.tsShows which locale, avatar, and screenshot value types are public package API
src/…/browser.tsDefines browser identifiers used by session-based browser icons
src/…/credit-card.tsDefines payment card provider identifiers used by credit card icons
src/…/flag.tsDefines country identifiers used by flag assets
src/…/timezone.tsDefines the IANA time zone choices available to screenshot requests
src/…/browser-theme.tsDefines light and dark screenshot browser themes
src/…/browser-permission.tsDefines permissions that can be granted during screenshot rendering
src/…/image-format.tsDefines screenshot output format choices
docs/…/get-screenshot.mdShows the full browser-context request as a consumer uses it
docs/…/list-countries.mdShows the basic locale catalog request