@joystick.js/node-canary 0.0.0-canary.453 → 0.0.0-canary.455
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 f 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
|
|
1
|
+
import p from"fs";import _ from"./dynamic_import.js";import f 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 _(f(`${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?f(`${t?.joystick_build_path}i18n/email`):f(`${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],o=a.find(g=>!!g.match(u));if(o){e=o;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
|
@@ -77,6 +77,7 @@ const get_translations = async (get_translations_options = {}) => {
|
|
|
77
77
|
const language_files_path = get_translations_options?.is_email ?
|
|
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
|
const language_files = (await path_exists(language_files_path) && fs.readdirSync(language_files_path)) || [];
|
|
81
82
|
const browser_languages = get_translations_options?.is_email ? [] : parse_browser_languages(get_translations_options?.req?.headers['accept-language']);
|
|
82
83
|
const language_preferences = get_language_preference_regexes(
|
|
@@ -85,6 +86,7 @@ const get_translations = async (get_translations_options = {}) => {
|
|
|
85
86
|
get_translations_options?.email_template_name
|
|
86
87
|
);
|
|
87
88
|
|
|
89
|
+
console.log({ language_files_path, language_files, language_preferences });
|
|
88
90
|
let matching_file = null;
|
|
89
91
|
|
|
90
92
|
for (let i = 0; i < language_preferences.length; i += 1) {
|