diff --git a/adapter/src/utils/useLocale.js b/adapter/src/utils/useLocale.js index 88ea800b..b1ee3349 100644 --- a/adapter/src/utils/useLocale.js +++ b/adapter/src/utils/useLocale.js @@ -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, @@ -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 } } diff --git a/docs/config/d2-config-js-reference.md b/docs/config/d2-config-js-reference.md index 8e19c4f7..25da59c8 100644 --- a/docs/config/d2-config-js-reference.md +++ b/docs/config/d2-config-js-reference.md @@ -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. |