smoonb 0.0.77 → 0.0.79
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/package.json
CHANGED
package/src/i18n/index.js
CHANGED
|
@@ -79,13 +79,13 @@ function detectSystemLocale(env) {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
|
-
* Detectar locale baseado em argumentos CLI, env e sistema
|
|
82
|
+
* Detectar locale baseado em argumentos CLI, .env.local, env e sistema
|
|
83
83
|
* @param {string[]} argv - Argumentos da linha de comando
|
|
84
84
|
* @param {NodeJS.ProcessEnv} env - Variáveis de ambiente
|
|
85
85
|
* @returns {string} - Código de locale (padrão: 'en')
|
|
86
86
|
*/
|
|
87
87
|
function detectLocale(argv = [], env = process.env) {
|
|
88
|
-
// 1. Verificar flag CLI --lang
|
|
88
|
+
// 1. Verificar flag CLI --lang (maior precedência)
|
|
89
89
|
const langIndex = argv.indexOf('--lang');
|
|
90
90
|
if (langIndex !== -1 && argv[langIndex + 1]) {
|
|
91
91
|
const normalized = normalizeLocale(argv[langIndex + 1]);
|
|
@@ -94,7 +94,36 @@ function detectLocale(argv = [], env = process.env) {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
// 2. Verificar
|
|
97
|
+
// 2. Verificar SMOONB_LANG do .env.local (síncrono para evitar problemas de inicialização)
|
|
98
|
+
try {
|
|
99
|
+
const envLocalPath = path.join(process.cwd(), '.env.local');
|
|
100
|
+
if (fs.existsSync(envLocalPath)) {
|
|
101
|
+
const envContent = fs.readFileSync(envLocalPath, 'utf8');
|
|
102
|
+
const envLines = envContent.replace(/\r\n/g, '\n').split('\n');
|
|
103
|
+
for (const line of envLines) {
|
|
104
|
+
const trimmed = line.trim();
|
|
105
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
106
|
+
const eqIndex = line.indexOf('=');
|
|
107
|
+
if (eqIndex === -1) continue;
|
|
108
|
+
const key = line.slice(0, eqIndex).trim();
|
|
109
|
+
if (key === 'SMOONB_LANG') {
|
|
110
|
+
let value = line.slice(eqIndex + 1).trim();
|
|
111
|
+
// Remove optional quotes
|
|
112
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
113
|
+
value = value.slice(1, -1);
|
|
114
|
+
}
|
|
115
|
+
const normalized = normalizeLocale(value);
|
|
116
|
+
if (normalized) {
|
|
117
|
+
return normalized;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
} catch {
|
|
123
|
+
// Ignorar erros ao ler .env.local (pode não existir ainda)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 3. Verificar variável de ambiente SMOONB_LANG
|
|
98
127
|
if (env.SMOONB_LANG) {
|
|
99
128
|
const normalized = normalizeLocale(env.SMOONB_LANG);
|
|
100
129
|
if (normalized) {
|
|
@@ -102,13 +131,13 @@ function detectLocale(argv = [], env = process.env) {
|
|
|
102
131
|
}
|
|
103
132
|
}
|
|
104
133
|
|
|
105
|
-
//
|
|
134
|
+
// 4. Verificar locale do sistema
|
|
106
135
|
const systemLocale = detectSystemLocale(env);
|
|
107
136
|
if (systemLocale) {
|
|
108
137
|
return systemLocale;
|
|
109
138
|
}
|
|
110
139
|
|
|
111
|
-
//
|
|
140
|
+
// 5. Fallback para inglês
|
|
112
141
|
return 'en';
|
|
113
142
|
}
|
|
114
143
|
|
package/src/i18n/locales/en.json
CHANGED
|
@@ -262,6 +262,10 @@
|
|
|
262
262
|
"env.mapping.backupCreated": "Backup of .env.local: {path}",
|
|
263
263
|
"env.mapping.fileNotFound": ".env.local file not found. It will be created during mapping.",
|
|
264
264
|
"env.mapping.updated": ".env.local updated successfully. No keys renamed; values synchronized.",
|
|
265
|
+
"env.language.selectDefault": "What is the default language?",
|
|
266
|
+
"env.language.english": "English",
|
|
267
|
+
"env.language.portuguese": "Portuguese (pt-BR)",
|
|
268
|
+
"env.language.saved": "Default language saved: {lang}",
|
|
265
269
|
|
|
266
270
|
"backup.components.edgeFunctions.title": "Edge Functions:",
|
|
267
271
|
"backup.components.edgeFunctions.description1": "We will delete existing functions in the supabase/functions folder, reset the link",
|
|
@@ -262,6 +262,10 @@
|
|
|
262
262
|
"env.mapping.backupCreated": "Backup do .env.local: {path}",
|
|
263
263
|
"env.mapping.fileNotFound": "Arquivo .env.local não encontrado. Será criado durante o mapeamento.",
|
|
264
264
|
"env.mapping.updated": ".env.local atualizado com sucesso. Nenhuma chave renomeada; valores sincronizados.",
|
|
265
|
+
"env.language.selectDefault": "Qual o idioma padrão?",
|
|
266
|
+
"env.language.english": "Inglês (English)",
|
|
267
|
+
"env.language.portuguese": "Português (pt-BR)",
|
|
268
|
+
"env.language.saved": "Idioma padrão salvo: {lang}",
|
|
265
269
|
|
|
266
270
|
"backup.components.edgeFunctions.title": "Edge Functions:",
|
|
267
271
|
"backup.components.edgeFunctions.description1": "Vamos apagar as funções existentes na pasta supabase/functions, fazer um reset no link",
|
|
@@ -208,6 +208,34 @@ async function mapEnvVariablesInteractively(env, expectedKeys) {
|
|
|
208
208
|
dePara[clientKey] = expected;
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
// Após processar todas as variáveis, perguntar sobre idioma padrão se SMOONB_OUTPUT_DIR foi processado
|
|
212
|
+
const outputDirProcessed = Object.values(dePara).includes('SMOONB_OUTPUT_DIR');
|
|
213
|
+
if (outputDirProcessed) {
|
|
214
|
+
const currentLang = finalEnv.SMOONB_LANG || '';
|
|
215
|
+
const { normalizeLocale } = require('../i18n');
|
|
216
|
+
|
|
217
|
+
const langChoices = [
|
|
218
|
+
{ name: getT('env.language.english'), value: 'en' },
|
|
219
|
+
{ name: getT('env.language.portuguese'), value: 'pt-BR' }
|
|
220
|
+
];
|
|
221
|
+
|
|
222
|
+
const defaultLang = currentLang ? normalizeLocale(currentLang) || 'en' : 'en';
|
|
223
|
+
const defaultIndex = langChoices.findIndex(c => c.value === defaultLang);
|
|
224
|
+
|
|
225
|
+
const { selectedLang } = await inquirer.prompt([{
|
|
226
|
+
type: 'list',
|
|
227
|
+
name: 'selectedLang',
|
|
228
|
+
message: getT('env.language.selectDefault'),
|
|
229
|
+
choices: langChoices,
|
|
230
|
+
default: defaultIndex >= 0 ? defaultIndex : 0,
|
|
231
|
+
loop: false,
|
|
232
|
+
prefix: ''
|
|
233
|
+
}]);
|
|
234
|
+
|
|
235
|
+
finalEnv.SMOONB_LANG = selectedLang;
|
|
236
|
+
console.log(chalk.green(`✅ ${getT('env.language.saved', { lang: selectedLang })}`));
|
|
237
|
+
}
|
|
238
|
+
|
|
211
239
|
return { finalEnv, dePara };
|
|
212
240
|
}
|
|
213
241
|
|