smoonb 0.0.81 → 0.0.83

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.
package/bin/smoonb.js CHANGED
@@ -275,7 +275,6 @@ if (options.lang) {
275
275
  const newI18n = initI18n(['--lang', forcedLocale], { ...process.env, SMOONB_LANG: forcedLocale });
276
276
  i18n = newI18n;
277
277
  t = newI18n.t;
278
- Object.assign(global.smoonbI18n, newI18n);
279
278
  }
280
279
 
281
280
  // Se nenhum comando foi fornecido, mostrar ajuda
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smoonb",
3
- "version": "0.0.81",
3
+ "version": "0.0.83",
4
4
  "description": "Complete Supabase backup and migration tool - EXPERIMENTAL VERSION - USE AT YOUR OWN RISK",
5
5
  "preferGlobal": false,
6
6
  "preventGlobalInstall": true,
package/src/i18n/index.js CHANGED
@@ -198,15 +198,13 @@ function loadCatalog(locale) {
198
198
  * @returns {string} - Texto traduzido
199
199
  */
200
200
  function t(id, vars = {}, locale = null) {
201
- // Determinar locale a usar
202
- const catalog = locale ? loadCatalog(locale) : (global.smoonbI18n?.catalog || loadCatalog('en'));
201
+ const localeToUse = locale || global.smoonbI18n?.locale || 'en';
202
+ const catalog = loadCatalog(localeToUse);
203
203
 
204
- // Buscar tradução
205
204
  let translation = catalog[id] || id;
206
205
 
207
- // Substituir placeholders nomeados (ex: {name}, {path})
208
206
  if (typeof translation === 'string' && Object.keys(vars).length > 0) {
209
- translation = translation.replace(/{(\w+)}/g, (match, key) => {
207
+ translation = translation.replace(/\{(\w+)\}/g, (match, key) => {
210
208
  return vars[key] !== undefined ? String(vars[key]) : match;
211
209
  });
212
210
  }
@@ -214,6 +212,16 @@ function t(id, vars = {}, locale = null) {
214
212
  return translation;
215
213
  }
216
214
 
215
+ let globalTranslator = null;
216
+
217
+ function ensureGlobalTranslator() {
218
+ if (!globalTranslator) {
219
+ globalTranslator = (id, vars) => t(id, vars, global.smoonbI18n?.locale);
220
+ }
221
+
222
+ return globalTranslator;
223
+ }
224
+
217
225
  /**
218
226
  * Inicializar i18n com locale detectado
219
227
  * @param {string[]} argv - Argumentos da linha de comando
@@ -224,12 +232,13 @@ function initI18n(argv = process.argv, env = process.env) {
224
232
  const locale = detectLocale(argv, env);
225
233
  const catalog = loadCatalog(locale);
226
234
 
227
- // Armazenar globalmente para acesso fácil
228
- global.smoonbI18n = {
229
- locale,
230
- catalog,
231
- t: (id, vars) => t(id, vars, locale)
232
- };
235
+ if (!global.smoonbI18n) {
236
+ global.smoonbI18n = {};
237
+ }
238
+
239
+ global.smoonbI18n.locale = locale;
240
+ global.smoonbI18n.catalog = catalog;
241
+ global.smoonbI18n.t = ensureGlobalTranslator();
233
242
 
234
243
  return global.smoonbI18n;
235
244
  }
@@ -84,7 +84,12 @@ async function mapEnvVariablesInteractively(env, expectedKeys) {
84
84
  };
85
85
  }
86
86
 
87
- const getT = global.smoonbI18n?.t || t;
87
+ // Função getT que sempre acessa global.smoonbI18n dinamicamente
88
+ // Isso permite que a mudança de idioma seja aplicada em tempo real
89
+ const getT = (id, vars) => {
90
+ const currentT = global.smoonbI18n?.t || t;
91
+ return currentT(id, vars);
92
+ };
88
93
 
89
94
  for (const expected of expectedKeys) {
90
95
  console.log(chalk.blue(`\n🔧 ${getT('env.mapping.title', { variable: expected })}`));
@@ -236,22 +241,24 @@ async function mapEnvVariablesInteractively(env, expectedKeys) {
236
241
 
237
242
  // Re-inicializar i18n com o novo idioma para aplicar mudança em tempo real
238
243
  const { initI18n } = require('../i18n');
239
- const newI18n = initI18n(process.argv, { ...process.env, SMOONB_LANG: selectedLang });
240
- Object.assign(global.smoonbI18n, newI18n);
244
+ initI18n(process.argv, { ...process.env, SMOONB_LANG: selectedLang });
241
245
 
242
- // Atualizar getT para usar o novo idioma (não redeclarar, apenas atualizar a referência)
243
- // getT foi declarado no escopo da função, então apenas atualizamos o global.smoonbI18n
244
- // e getT continuará funcionando através do global.smoonbI18n?.t
245
- const updatedGetT = global.smoonbI18n?.t || t;
246
- console.log(chalk.green(`✅ ${updatedGetT('env.language.saved', { lang: selectedLang })}`));
247
- console.log(chalk.cyan(`🌐 ${updatedGetT('env.language.applied')}`));
246
+ // getT agora funciona dinamicamente, sempre acessando global.smoonbI18n?.t
247
+ // Então não precisamos atualizar nada, apenas usar getT normalmente
248
+ console.log(chalk.green(`✅ ${getT('env.language.saved', { lang: selectedLang })}`));
249
+ console.log(chalk.cyan(`🌐 ${getT('env.language.applied')}`));
248
250
  }
249
251
 
250
252
  return { finalEnv, dePara };
251
253
  }
252
254
 
253
255
  async function askComponentsFlags() {
254
- const getT = global.smoonbI18n?.t || t;
256
+ // Função getT que sempre acessa global.smoonbI18n dinamicamente
257
+ // Isso permite que a mudança de idioma seja aplicada em tempo real
258
+ const getT = (id, vars) => {
259
+ const currentT = global.smoonbI18n?.t || t;
260
+ return currentT(id, vars);
261
+ };
255
262
 
256
263
  // Explicação sobre Edge Functions
257
264
  console.log(chalk.cyan(`\n⚡ ${getT('backup.components.edgeFunctions.title')}`));