Skip to content

Commit

Permalink
fix: Use documentLocaleSettings (#156)
Browse files Browse the repository at this point in the history
* Use documentLocaleSettings

* Add documentLocaleSettings to lang tests

* Just check against the current document lang

* Re-add documentLocaleSettings, but read-only
  • Loading branch information
bearfriend authored Sep 1, 2023
1 parent 327731d commit 0bdfd5d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
"access": "public"
},
"dependencies": {
"@rollup/plugin-node-resolve": "^15",
"@brightspace-ui/intl": "^3",
"@open-wc/testing": "^3",
"@rollup/plugin-node-resolve": "^15",
"@web/config-loader": "^0.2",
"@web/dev-server": "^0.2",
"@web/rollup-plugin-html": "^2",
Expand Down
11 changes: 7 additions & 4 deletions src/browser/reset.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { sendMouse, setViewport } from '@web/test-runner-commands';
import { getDocumentLocaleSettings } from '@brightspace-ui/intl/lib/common.js';
import { nextFrame } from '@open-wc/testing';

const DEFAULT_LANG = 'en',
DEFAULT_MATHJAX_RENDER_LATEX = false,
DEFAULT_VIEWPORT_HEIGHT = 800,
DEFAULT_VIEWPORT_WIDTH = 800;

let currentLang = undefined,
const documentLocaleSettings = getDocumentLocaleSettings();

let
currentMathjaxRenderLatex = DEFAULT_MATHJAX_RENDER_LATEX,
currentRtl = false,
currentViewportHeight = 0,
Expand Down Expand Up @@ -57,9 +60,9 @@ export async function reset(opts = {}) {
currentRtl = opts.rtl;
}

if (opts.lang !== currentLang) {
document.documentElement.setAttribute('lang', opts.lang);
currentLang = opts.lang;
opts.lang ??= '';
if (documentLocaleSettings.lamguage !== opts.lang) {
document.documentElement.lang = opts.lang;
awaitNextFrame = true;
}

Expand Down

0 comments on commit 0bdfd5d

Please sign in to comment.