Skip to content

Commit 6efd5ae

Browse files
committed
fix: correct path issues with dyn loaded locales
1 parent 2d728ae commit 6efd5ae

File tree

10 files changed

+28
-19
lines changed

10 files changed

+28
-19
lines changed

demo/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
</head>
1414
<body>
1515
<oscd-shell locale="de"> </oscd-shell>
16-
<script type="module" src="index.js"></script>
16+
<script type="module">
17+
// Known issue, scoped registry polyfill doesn't load as fast as oscd-shell, causing oscs-shell to fail.
18+
// To safeguard, we await the polyfill first, then load the rest.
19+
await import('@webcomponents/scoped-custom-element-registry');
20+
await import('../dist/oscd-shell.js');
21+
await import('./index.js');
22+
</script>
1723

1824
<style>
1925
* {

demo/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import '@webcomponents/scoped-custom-element-registry';
2-
import '../dist/oscd-shell.js';
1+
// import '@webcomponents/scoped-custom-element-registry';
2+
// import '../dist/oscd-shell.js';
33
import OscdMenuOpen from '@omicronenergy/oscd-menu-open';
44
import OscdMenuSave from '@omicronenergy/oscd-menu-save';
55
import {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
"localize": "lit-localize build",
3939
"build": "rimraf dist && mkdir dist && npm run extract && npm run localize && npm run analyze -- --exclude dist && tsc ",
4040
"bundle": "rimraf dist && npm run extract && npm run localize && rollup -c rollup.config.js",
41-
"start": "npm run build && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds --open '/demo/' --node-resolve\"",
42-
"start:bundle": "npm run bundle && concurrently -k -r \"rollup -c rollup.config.js --watch\" \"wds --open '/dist/demo/' --watch\"",
41+
"start": "npm run build && concurrently -k \"tsc --watch --preserveWatchOutput\" \"wds --open '/demo/' --node-resolve\"",
42+
"start:bundle": "npm run bundle && concurrently -k -r \"rollup -c rollup.config.js --watch\" \"wds --root-dir dist --app-index demo/index.html --open '/demo/' --watch\"",
4343
"test": "npm run build && wtr --coverage --group unit",
4444
"test:watch": "npm run build && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wtr --coverage --watch --group unit\"",
4545
"analyze": "cem analyze --litelement --exclude demo/* --exclude dist/* --exclude *.spec.ts --exclude *.test.ts --exclude coverage/*",

rollup.config.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const locales = readdirSync('src/locales').map(locale => ({
2626
}));
2727

2828
export default [
29+
...locales,
2930
{
3031
input: 'src/oscd-shell.ts',
3132
output: {
@@ -39,6 +40,7 @@ export default [
3940
/** Resolve bare module imports */
4041
nodeResolve(),
4142
typescript(),
43+
importMetaAssets({ warnOnError: true }),
4244
],
4345
},
4446
{
@@ -54,6 +56,7 @@ export default [
5456
/** Resolve bare module imports */
5557
nodeResolve(),
5658
typescript(),
59+
importMetaAssets({ warnOnError: true }),
5760
],
5861
},
5962
{
@@ -65,20 +68,23 @@ export default [
6568
}),
6669
copy({
6770
targets: [
68-
{ src: 'demo/*.*', dest: 'dist/demo' },
69-
// Add more patterns if you have more assets
71+
{
72+
src: 'demo/*.*',
73+
dest: 'dist/demo',
74+
ignore: ['demo/index.js', 'demo/index.html'],
75+
},
7076
],
7177
verbose: true,
7278
flatten: false,
7379
}),
7480
nodeResolve(),
7581
typescript(demoTsconfig),
76-
importMetaAssets(),
82+
importMetaAssets({ warnOnError: true }),
7783
],
7884
output: {
7985
dir: 'dist/demo',
8086
format: 'es',
8187
sourcemap: true,
8288
},
8389
},
84-
].concat(locales);
90+
];

src/landing-page/landing-page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { OscdIcon } from '@omicronenergy/oscd-ui/icon/OscdIcon.js';
77
import { OscdTextButton } from '@omicronenergy/oscd-ui/button/OscdTextButton.js';
88

99
import { PluginEntry } from '../oscd-shell.js';
10-
import { LocaleTag } from '../utils/localization.js';
10+
import { LocaleTag } from '../localization.js';
1111
import { OscdElevation } from '@omicronenergy/oscd-ui/elevation/OscdElevation.js';
1212

1313
declare global {
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { configureLocalization } from '@lit/localize';
2-
import { allLocales, sourceLocale, targetLocales } from '../locales.js';
2+
import { allLocales, sourceLocale, targetLocales } from './locales.js';
33
export type LocaleTag = (typeof allLocales)[number];
44
export type Translation = (typeof targetLocales)[number];
55
export type Translations = Record<Translation, string>;
@@ -19,10 +19,7 @@ const { getLocale, setLocale } =
1919
sourceLocale,
2020
targetLocales,
2121
loadLocale: _locale => {
22-
return import(
23-
/* @vite-ignore */ new URL(`./locales/${_locale}.js`, import.meta.url)
24-
.href
25-
);
22+
return import(new URL(`./locales/de.js`, import.meta.url).href);
2623
},
2724
});
2825

src/menus/files-menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { OscdMenu } from '@omicronenergy/oscd-ui/menu/OscdMenu.js';
88
import { OscdMenuItem } from '@omicronenergy/oscd-ui/menu/OscdMenuItem.js';
99
import { OscdTextButton } from '@omicronenergy/oscd-ui/button/OscdTextButton.js';
1010

11-
import { LocaleTag } from '../utils/localization.js';
11+
import { LocaleTag } from '../localization.js';
1212

1313
declare global {
1414
interface HTMLElementTagNameMap {

src/menus/plugins-menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { OscdIcon } from '@omicronenergy/oscd-ui/icon/OscdIcon.js';
88
import { OscdMenu } from '@omicronenergy/oscd-ui/menu/OscdMenu.js';
99
import { OscdMenuItem } from '@omicronenergy/oscd-ui/menu/OscdMenuItem.js';
1010

11-
import { LocaleTag, Translation } from '../utils/localization.js';
11+
import { LocaleTag, Translation } from '../localization.js';
1212
import { PluginEntry } from '../oscd-shell.js';
1313

1414
declare global {

src/oscd-shell.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
LocaleTag,
2121
setLocale,
2222
Translations,
23-
} from './utils/localization.js';
23+
} from './localization.js';
2424
import { theming } from './theming.js';
2525
import { EditorPluginsPanel } from './side-panel/editor-plugins-panel.js';
2626
import { PluginsMenu } from './menus/plugins-menu.js';

src/side-panel/editor-plugins-panel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { OscdIcon } from '@omicronenergy/oscd-ui/icon/OscdIcon.js';
88
import { OscdList } from '@omicronenergy/oscd-ui/list/OscdList.js';
99
import { OscdListItem } from '@omicronenergy/oscd-ui/list/OscdListItem.js';
1010

11-
import { LocaleTag, Translation } from '../utils/localization.js';
11+
import { LocaleTag, Translation } from '../localization.js';
1212
import { classMap } from 'lit/directives/class-map.js';
1313
import { PluginEntry } from '../oscd-shell.js';
1414

0 commit comments

Comments
 (0)