smoonb 0.0.82 → 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.82",
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
  }
@@ -241,8 +241,7 @@ async function mapEnvVariablesInteractively(env, expectedKeys) {
241
241
 
242
242
  // Re-inicializar i18n com o novo idioma para aplicar mudança em tempo real
243
243
  const { initI18n } = require('../i18n');
244
- const newI18n = initI18n(process.argv, { ...process.env, SMOONB_LANG: selectedLang });
245
- Object.assign(global.smoonbI18n, newI18n);
244
+ initI18n(process.argv, { ...process.env, SMOONB_LANG: selectedLang });
246
245
 
247
246
  // getT agora funciona dinamicamente, sempre acessando global.smoonbI18n?.t
248
247
  // Então não precisamos atualizar nada, apenas usar getT normalmente