@joystick.js/node-canary 0.0.0-canary.454 → 0.0.0-canary.456
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import p from"fs";import _ from"./dynamic_import.js";import
|
|
1
|
+
import p from"fs";import _ from"./dynamic_import.js";import o from"./get_platform_safe_path.js";import h from"../app/settings/load.js";import d from"./path_exists.js";import m from"./types.js";const l=h(),$=async(t="",n="",a="")=>{const r=await _(`${n}/i18n/${t}?v=${new Date().getTime()}`);if(console.log({language_file:r}),r&&m.is_object(r)){const e=r[a];return e||r}return{}},w=(t="",n=[],a="")=>{let r=[];t&&r.push(t);const s=n?.filter(e=>!e?.includes("*"));return r.push(...s),(l?.config?.i18n?.defaultLanguage||l?.config?.i18n?.default_language)&&r.push(l?.config?.i18n?.defaultLanguage||l?.config?.i18n?.default_language),r?.flatMap(e=>{const i=[e];return e?.length===2&&i.push(`${e.substring(0,2)}-`),e?.length>2&&(i.push(`${e?.split("-")[0]}`),i.push(`${e?.split("-")[0]}-`)),i})?.map(e=>e[e.length-1]==="-"?new RegExp(a?`^${a}_${e}[A-Z]+.js`:`^${e}[A-Z]+.js`,"g"):new RegExp(a?`^${a}_${e}.js`:`^${e}.js`,"g"))},b=(t="")=>t.split(",")?.map(a=>a.split(";")[0]),j=async(t={})=>{const n=t?.is_email?o(`${t?.joystick_build_path}i18n/email`):o(`${t?.joystick_build_path}i18n`),a=await d(n)&&p.readdirSync(n)||[],r=t?.is_email?[]:b(t?.req?.headers["accept-language"]),s=w(t?.req?.context?.user?.language,r,t?.email_template_name);console.log({language_files_path:n,language_files:a,language_preferences:s});let e=null;for(let c=0;c<s.length;c+=1){const u=s[c],f=a.find(g=>!!g.match(u));if(f){e=f;break}}return(e?await $(e,t?.joystick_build_path,t?.render_component_path):null)||{}};var E=j;export{E as default};
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ const settings = load_settings();
|
|
|
9
9
|
|
|
10
10
|
const get_translations_file = async (language_file_path = '', joystick_build_path = '', render_component_path = '') => {
|
|
11
11
|
const language_file = await dynamic_import(
|
|
12
|
-
|
|
12
|
+
`${joystick_build_path}/i18n/${language_file_path}?v=${new Date().getTime()}`
|
|
13
13
|
);
|
|
14
14
|
|
|
15
15
|
console.log({ language_file });
|
|
@@ -78,7 +78,6 @@ const get_translations = async (get_translations_options = {}) => {
|
|
|
78
78
|
get_platform_safe_path(`${get_translations_options?.joystick_build_path}i18n/email`) :
|
|
79
79
|
get_platform_safe_path(`${get_translations_options?.joystick_build_path}i18n`);
|
|
80
80
|
|
|
81
|
-
console.log({ language_files_path });
|
|
82
81
|
const language_files = (await path_exists(language_files_path) && fs.readdirSync(language_files_path)) || [];
|
|
83
82
|
const browser_languages = get_translations_options?.is_email ? [] : parse_browser_languages(get_translations_options?.req?.headers['accept-language']);
|
|
84
83
|
const language_preferences = get_language_preference_regexes(
|
|
@@ -87,6 +86,7 @@ const get_translations = async (get_translations_options = {}) => {
|
|
|
87
86
|
get_translations_options?.email_template_name
|
|
88
87
|
);
|
|
89
88
|
|
|
89
|
+
console.log({ language_files_path, language_files, language_preferences });
|
|
90
90
|
let matching_file = null;
|
|
91
91
|
|
|
92
92
|
for (let i = 0; i < language_preferences.length; i += 1) {
|