smoonb 0.0.83 → 0.0.84

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,6 +275,7 @@ 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);
278
279
  }
279
280
 
280
281
  // 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.83",
3
+ "version": "0.0.84",
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,13 +198,15 @@ function loadCatalog(locale) {
198
198
  * @returns {string} - Texto traduzido
199
199
  */
200
200
  function t(id, vars = {}, locale = null) {
201
- const localeToUse = locale || global.smoonbI18n?.locale || 'en';
202
- const catalog = loadCatalog(localeToUse);
201
+ // Determinar locale a usar
202
+ const catalog = locale ? loadCatalog(locale) : (global.smoonbI18n?.catalog || loadCatalog('en'));
203
203
 
204
+ // Buscar tradução
204
205
  let translation = catalog[id] || id;
205
206
 
207
+ // Substituir placeholders nomeados (ex: {name}, {path})
206
208
  if (typeof translation === 'string' && Object.keys(vars).length > 0) {
207
- translation = translation.replace(/\{(\w+)\}/g, (match, key) => {
209
+ translation = translation.replace(/{(\w+)}/g, (match, key) => {
208
210
  return vars[key] !== undefined ? String(vars[key]) : match;
209
211
  });
210
212
  }
@@ -212,16 +214,6 @@ function t(id, vars = {}, locale = null) {
212
214
  return translation;
213
215
  }
214
216
 
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
-
225
217
  /**
226
218
  * Inicializar i18n com locale detectado
227
219
  * @param {string[]} argv - Argumentos da linha de comando
@@ -232,13 +224,12 @@ function initI18n(argv = process.argv, env = process.env) {
232
224
  const locale = detectLocale(argv, env);
233
225
  const catalog = loadCatalog(locale);
234
226
 
235
- if (!global.smoonbI18n) {
236
- global.smoonbI18n = {};
237
- }
238
-
239
- global.smoonbI18n.locale = locale;
240
- global.smoonbI18n.catalog = catalog;
241
- global.smoonbI18n.t = ensureGlobalTranslator();
227
+ // Armazenar globalmente para acesso fácil
228
+ global.smoonbI18n = {
229
+ locale,
230
+ catalog,
231
+ t: (id, vars) => t(id, vars, locale)
232
+ };
242
233
 
243
234
  return global.smoonbI18n;
244
235
  }
@@ -266,7 +266,7 @@
266
266
  "env.language.english": "English",
267
267
  "env.language.portuguese": "Portuguese (pt-BR)",
268
268
  "env.language.saved": "Default language saved: {lang}",
269
- "env.language.applied": "Language applied! The next messages will be displayed in the selected language.",
269
+ "env.language.note": "Note: The language change will be effective in the next commands. The current process will continue in the initial language.",
270
270
 
271
271
  "backup.components.edgeFunctions.title": "Edge Functions:",
272
272
  "backup.components.edgeFunctions.description1": "We will delete existing functions in the supabase/functions folder, reset the link",
@@ -266,7 +266,7 @@
266
266
  "env.language.english": "Inglês (English)",
267
267
  "env.language.portuguese": "Português (pt-BR)",
268
268
  "env.language.saved": "Idioma padrão salvo: {lang}",
269
- "env.language.applied": "Idioma aplicado! As próximas mensagens serão exibidas no idioma selecionado.",
269
+ "env.language.note": "Nota: A mudança de idioma será efetiva nos próximos comandos. O processo atual continuará no idioma inicial.",
270
270
 
271
271
  "backup.components.edgeFunctions.title": "Edge Functions:",
272
272
  "backup.components.edgeFunctions.description1": "Vamos apagar as funções existentes na pasta supabase/functions, fazer um reset no link",
@@ -84,12 +84,7 @@ async function mapEnvVariablesInteractively(env, expectedKeys) {
84
84
  };
85
85
  }
86
86
 
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
- };
87
+ const getT = global.smoonbI18n?.t || t;
93
88
 
94
89
  for (const expected of expectedKeys) {
95
90
  console.log(chalk.blue(`\n🔧 ${getT('env.mapping.title', { variable: expected })}`));
@@ -238,27 +233,15 @@ async function mapEnvVariablesInteractively(env, expectedKeys) {
238
233
  }]);
239
234
 
240
235
  finalEnv.SMOONB_LANG = selectedLang;
241
-
242
- // Re-inicializar i18n com o novo idioma para aplicar mudança em tempo real
243
- const { initI18n } = require('../i18n');
244
- initI18n(process.argv, { ...process.env, SMOONB_LANG: selectedLang });
245
-
246
- // getT agora funciona dinamicamente, sempre acessando global.smoonbI18n?.t
247
- // Então não precisamos atualizar nada, apenas usar getT normalmente
248
236
  console.log(chalk.green(`✅ ${getT('env.language.saved', { lang: selectedLang })}`));
249
- console.log(chalk.cyan(`🌐 ${getT('env.language.applied')}`));
237
+ console.log(chalk.yellow(`💡 ${getT('env.language.note')}`));
250
238
  }
251
239
 
252
240
  return { finalEnv, dePara };
253
241
  }
254
242
 
255
243
  async function askComponentsFlags() {
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
- };
244
+ const getT = global.smoonbI18n?.t || t;
262
245
 
263
246
  // Explicação sobre Edge Functions
264
247
  console.log(chalk.cyan(`\n⚡ ${getT('backup.components.edgeFunctions.title')}`));