Skip to content

Commit

Permalink
move i18n imports to their respective frontend pages
Browse files Browse the repository at this point in the history
  • Loading branch information
terrablue committed Aug 4, 2024
1 parent 865123d commit 83fff10
Show file tree
Hide file tree
Showing 27 changed files with 75 additions and 27 deletions.
10 changes: 6 additions & 4 deletions packages/i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
}
},
"exports": {
"./*/locale": "./src/server/*/locale.js",
"./*": "./src/server/*/index.js",
"./core/*": {
"@primate/lt": "./src/public/*.js",
"default": "./src/public/*.js"
},
".": {
"runtime": "./src/runtime.js",
"default": "./src/default.js"
"runtime": "./src/public/runtime.js",
"default": "./src/public/default.js"
}
}
}
1 change: 1 addition & 0 deletions packages/i18n/src/private/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "Primate-I18N-Locale";
3 changes: 2 additions & 1 deletion packages/i18n/src/private/hook/handle.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import header from "#header";
import name from "#name";
import { OK } from "@rcompat/http/status";

Expand All @@ -14,7 +15,7 @@ export default ({ env }) => (request, next) => {
return next(request);
}

const set_locale = request.headers.get("primate-i18n-locale");
const set_locale = request.headers.get(header);

if (set_locale === undefined) {
return next(request);
Expand Down
6 changes: 3 additions & 3 deletions packages/i18n/src/private/save.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import header from "#header";

export default locale => fetch("/", {
headers: {
"Primate-I18N-Locale": locale,
},
headers: { [header]: locale },
method: "post",
body: null,
});
File renamed without changes.
1 change: 1 addition & 0 deletions packages/i18n/src/public/resolve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "#resolve";
File renamed without changes.
1 change: 1 addition & 0 deletions packages/i18n/src/public/save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "#save";
12 changes: 11 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@
"@rcompat/platform": "^0.3.0"
},
"peerDependencies": {
"@primate/i18n": "workspace:^",
"primate": "workspace:^",
"react": "18",
"react-dom": "18"
},
"peerDependenciesMeta": {
"@primate/i18n": {
"optional": true
}
},
"type": "module",
"imports": {
"#*": {
Expand All @@ -50,14 +56,18 @@
"#client/*": {
"@primate/lt": "./src/private/client/*.js",
"default": "./src/private/client/*.js"
},
"#i18n/*": {
"@primate/lt": "./src/private/i18n/*.js",
"default": "./src/private/i18n/*.js"
}
},
"exports": {
".": {
"runtime": "./src/public/runtime.js",
"default": "./src/public/default.js"
},
"./head": "./src/public/head.js",
"./*": "./src/public/*.js",
"./context/*": "./src/public/context/*.js"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import resolve from "#resolve";
import AppContext from "@primate/react/context/app";
import AppContext from "#context/app";
import locale_store from "#i18n/locale";
import resolve from "@primate/i18n/core/resolve";
import { useContext } from "react";
import locale_store from "./locale.js";

export default (key, placeholders) => {
locale_store.init();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import save from "#save";
import AppContext from "@primate/react/context/app";
import AppContext from "#context/app";
import save from "@primate/i18n/core/save";
import { useContext } from "react";

const $ = {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/public/head.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import HeadContext from "@primate/react/context/head";
import HeadContext from "#context/head";
import platform from "@rcompat/platform";
import { Component } from "react";

Expand Down
1 change: 1 addition & 0 deletions packages/react/src/public/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "#i18n/index";
1 change: 1 addition & 0 deletions packages/react/src/public/locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "#i18n/locale";
12 changes: 11 additions & 1 deletion packages/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@
},
"peerDependencies": {
"@babel/core": "7",
"@primate/i18n": "workspace:^",
"babel-preset-solid": "1",
"primate": "workspace:^",
"solid-js": "1"
},
"peerDependenciesMeta": {
"@primate/i18n": {
"optional": true
}
},
"type": "module",
"imports": {
"#*": {
Expand All @@ -51,14 +57,18 @@
"#client/*": {
"@primate/lt": "./src/private/client/*.js",
"default": "./src/private/client/*.js"
},
"#i18n/*": {
"@primate/lt": "./src/private/i18n/*.js",
"default": "./src/private/i18n/*.js"
}
},
"exports": {
".": {
"runtime": "./src/public/runtime.js",
"default": "./src/public/default.js"
},
"./head": "./src/public/head.js",
"./*": "./src/public/*.js",
"./context/*": "./src/public/context/*.js"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import resolve from "#resolve";
import AppContext from "@primate/solid/context/app";
import resolve from "@primate/i18n/core/resolve";
import AppContext from "#context/app";
import { useContext } from "solid-js";
import locale_store from "./locale.js";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import save from "#save";
import AppContext from "@primate/solid/context/app";
import AppContext from "#context/app";
import save from "@primate/i18n/core/save";
import { useContext } from "solid-js";

const $ = {
Expand Down
1 change: 1 addition & 0 deletions packages/solid/src/public/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "#i18n/index";
1 change: 1 addition & 0 deletions packages/solid/src/public/locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "#i18n/locale";
13 changes: 12 additions & 1 deletion packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@
"@rcompat/fs": "^0.4.0"
},
"peerDependencies": {
"@primate/i18n": "workspace:^",
"primate": "workspace:^",
"svelte": "4"
},
"peerDependenciesMeta": {
"@primate/i18n": {
"optional": true
}
},
"type": "module",
"imports": {
"#*": {
Expand All @@ -43,12 +49,17 @@
"#client/*": {
"@primate/lt": "./src/private/client/*.js",
"default": "./src/private/client/*.js"
},
"#i18n/*": {
"@primate/lt": "./src/private/i18n/*.js",
"default": "./src/private/i18n/*.js"
}
},
"exports": {
".": {
"runtime": "./src/public/runtime.js",
"default": "./src/public/default.js"
}
},
"./*": "./src/public/*.js"
}
}
3 changes: 2 additions & 1 deletion packages/svelte/src/private/client/create-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ export default length => {
return `
<script>
import { afterUpdate, setContext } from "svelte";
import context_name from "@primate/svelte/context-name";
export let components;
export let data;
export let request;
export let context;
export let update = () => undefined;
setContext("__primate__", context);
setContext(context_name, context);
afterUpdate(update);
</script>
Expand Down
1 change: 1 addition & 0 deletions packages/svelte/src/private/context-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "__PRMT__";
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import resolve from "#resolve";
import context_name from "#context-name";
import locale_store from "#i18n/locale";
import resolve from "@primate/i18n/core/resolve";
import { getContext } from "svelte";
import { derived } from "svelte/store";
import locale_store from "./locale.js";

export default derived(locale_store, locale => (key, placeholders) => {
const { locales } = getContext("__primate__").i18n;
const { locales } = getContext(context_name).i18n;
return resolve(locales[locale], key, placeholders);
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import save from "#save";
import context_name from "#context-name";
import save from "@primate/i18n/core/save";
import { getContext } from "svelte";
import { writable } from "svelte/store";

const store = writable("", set => {
const { locale } = getContext("__primate__").i18n;
const { locale } = getContext(context_name).i18n;
set(locale);

return () => undefined;
Expand Down
1 change: 1 addition & 0 deletions packages/svelte/src/public/context-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "#context-name";
1 change: 1 addition & 0 deletions packages/svelte/src/public/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "#i18n/index";
1 change: 1 addition & 0 deletions packages/svelte/src/public/locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "#i18n/locale";

0 comments on commit 83fff10

Please sign in to comment.