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:
| Service | System purpose | Main result |
|---|---|---|
Locale | Resolve the caller's regional context and provide standard locale catalogs | Typed locale objects and lists |
Avatars | Create or fetch display-ready visual assets | Image 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.
| Catalog | Product use | Record information |
|---|---|---|
| Locale codes | Choose supported language or locale labels | ISO 639-1 code and name |
| Continents | Group or filter countries | Name and two-letter code |
| Countries | Build country selectors and regional filters | Name and ISO 3166-1 alpha-2 code |
| European Union countries | Limit a selector to current EU members | Country name and code |
| Country phone codes | Build phone country-code choices | Phone code with country identity |
| Currencies | Format prices and money input | Code, symbols, names, decimal digits, and rounding |
| Languages | Build language selectors | Code, 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.
| Asset | Input | Display purpose |
|---|---|---|
| Browser icon | Browser code from a user session | Show the browser used by a user |
| Credit card icon | Credit card provider code | Show a payment card provider |
| Flag | ISO 3166-1 alpha-2 country code | Show country identity |
| Initials avatar | Optional name | Provide a fallback user image; the service can use the current user's name or email |
| Profile photo | User ID, hashed email, or name | Resolve the best available profile image with fallbacks |
| QR image | Plain text | Share a link or other encoded text as a scannable image |
| Favicon | Remote website URL | Show a site's favorite icon |
| Image | Remote image URL | Fetch and resize a remote image for display |
| Screenshot | Website URL and browser context | Capture 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
Modelslist or record shape aligned. A field rename can break catalog consumers without changing the request name. - Keep browser session codes and the
Browservalues 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
| Trigger | Consequence | Guard |
|---|---|---|
| A required browser code, credit card code, remote URL, QR text, or screenshot URL is missing | The client raises an AppwriteException before it can produce an asset | Treat 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 request | Use the supported enum code values rather than path-like values |
| A favicon or image source needs an HTTP redirect | The remote asset request does not reach the redirected resource | Pass the final usable URL when the source does not serve the asset directly |
A raw email address is supplied as emailHash | External avatar lookup receives a value that is not the required hash and the expected profile image may not resolve | Send only the SHA-256 hash of the lowercase, trimmed email |
| A locale consumer assumes optional location fields always exist | Missing city, time zone, postal code, or network data causes empty or invalid UI values | Use 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 setting | The rendered page can differ from the intended browser state or the request can fail | Use 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 resolution | The stored placeholder remains the user's selected photo and lower-priority sources stay hidden | Treat deletion as a persistent placeholder choice; upload a new photo to restore custom-photo priority |
| An image response is handled as JSON | The app cannot display the returned asset bytes | Use the binary result as image data or use the matching URL helper |
Key files
| File | Why to read it |
|---|---|
| src/…/locale.ts | Defines the location request and the locale reference catalogs |
| src/models.ts | Defines the locale context, catalog records, and list shapes returned to callers |
| src/…/avatars.ts | Defines the asset families, profile-photo resolution, profile-photo lifecycle, screenshot context, binary results, and URL access paths |
| src/index.ts | Shows which locale, avatar, and screenshot value types are public package API |
| src/…/browser.ts | Defines browser identifiers used by session-based browser icons |
| src/…/credit-card.ts | Defines payment card provider identifiers used by credit card icons |
| src/…/flag.ts | Defines country identifiers used by flag assets |
| src/…/timezone.ts | Defines the IANA time zone choices available to screenshot requests |
| src/…/browser-theme.ts | Defines light and dark screenshot browser themes |
| src/…/browser-permission.ts | Defines permissions that can be granted during screenshot rendering |
| src/…/image-format.ts | Defines screenshot output format choices |
| docs/…/get-screenshot.md | Shows the full browser-context request as a consumer uses it |
| docs/…/list-countries.md | Shows the basic locale catalog request |