Skip to content

Commit

Permalink
chore: update logic for locales
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Mar 1, 2024
1 parent f9f3fbc commit 4656a3e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
25 changes: 18 additions & 7 deletions adapter/src/utils/useLocale.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useDataQuery } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import { useState, useEffect } from 'react'
import { useState, useEffect, useMemo } from 'react'
import {
setI18nLocale,
parseLocale,
Expand Down Expand Up @@ -62,14 +62,25 @@ const loginConfigQuery = {
resource: 'loginConfig',
},
}

export const useSystemDefaultLocale = () => {
// TO-DO: system language query (not currently available)
// system language from loginConfiqQuery
const { loading, data, error } = useDataQuery(loginConfigQuery)
// use uiLocale from query, if not fall back to window.navigator.language
// do not triger error boundary for login app
const locale = useLocale(
(data || error) &&
(data?.loginConfig?.uiLocale || window.navigator.language)
// set userSettings to use system locale by default
const localeInformation = useMemo(
() => ({
userSettings: {
keyUiLocale:
data &&
(data?.loginConfig?.uiLocale || window.navigator.language),
},
configDirection: 'auto',
}),
[data]
)
const locale = useLocale(localeInformation)
if (error) {
console.error(error)
}
return { loading: loading || !locale, locale }
}
2 changes: 1 addition & 1 deletion docs/config/d2-config-js-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The following configuration properties are supported:

| Property | Type | Default | Description |
| :--------------------: | :---------------------------: | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **type** | _string_ | **app** | Either **app**, **login_app** or **lib** |
| **type** | _string_ | **app** | Either **app**, **login_app** or **lib** |
| **name** | _string_ | `pkg.name` | A short, machine-readable unique name for this app |
| **title** | _string_ | `config.name` | The human-readable application title, which will appear in the HeaderBar |
| **direction** | `'ltr'`, `'rtl'`, or `'auto'` | `'ltr'` | Sets the `dir` HTML attribute on the `document` of the app. If set to `'auto'`, the direction will be inferred from the current user's UI locale setting. The header bar will always be considered 'auto' and is unaffected by this setting. |
Expand Down

0 comments on commit 4656a3e

Please sign in to comment.