@miphamai/cli 0.20.0 → 0.20.1

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miphamai/cli",
3
- "version": "0.20.0",
3
+ "version": "0.20.1",
4
4
  "description": "Mipham Code — Multi-model open-core intelligent coding terminal by MiphamAI",
5
5
  "keywords": [
6
6
  "ai",
@@ -18,10 +18,10 @@ import { getBackgroundAgentRegistry } from '../agent/background-registry'
18
18
  import { RulesLoader } from './rules-loader'
19
19
  import { UsageTracker } from './usage-tracker'
20
20
  import { buildRequest, sendInferenceCheck, isInferenceHookEnabled } from './inference-hook'
21
- import { createT } from '@mipham/shared/i18n/t'
22
- import enUS from '@mipham/shared/i18n/locales/en-US.json'
23
- import zhCN from '@mipham/shared/i18n/locales/zh-CN.json'
24
- import type { TranslationMap } from '@mipham/shared/i18n/types'
21
+ import { createT } from '../i18n-core/t'
22
+ import enUS from '../i18n-core/locales/en-US.json'
23
+ import zhCN from '../i18n-core/locales/zh-CN.json'
24
+ import type { TranslationMap } from '../i18n-core/types'
25
25
 
26
26
  const bundles: Record<string, TranslationMap> = {
27
27
  'en-US': enUS as TranslationMap,
@@ -516,9 +516,9 @@ export class QueryEngine {
516
516
  }
517
517
  // Script failed — continue looping
518
518
  yield {
519
- type: 'text',
520
- content: t('system.goal.failed_continuing', { loop: String(loop) }),
521
- }
519
+ type: 'text',
520
+ content: t('system.goal.failed_continuing', { loop: String(loop) }),
521
+ }
522
522
  continue
523
523
  }
524
524
 
@@ -1,5 +1,5 @@
1
1
  import React, { createContext, useContext } from 'react'
2
- import type { Locale } from '@mipham/shared/i18n/types'
2
+ import type { Locale } from './i18n-core/types'
3
3
 
4
4
  export interface I18nContextValue {
5
5
  locale: Locale
@@ -17,11 +17,7 @@ export function I18nProvider({
17
17
  t: (key: string, params?: Record<string, string>) => string
18
18
  children: React.ReactNode
19
19
  }) {
20
- return React.createElement(
21
- I18nContext.Provider,
22
- { value: { locale, t } },
23
- children,
24
- )
20
+ return React.createElement(I18nContext.Provider, { value: { locale, t } }, children)
25
21
  }
26
22
 
27
23
  export function useI18n(): I18nContextValue {
@@ -0,0 +1,54 @@
1
+ import type { Locale } from './types'
2
+ import { execSync } from 'node:child_process'
3
+
4
+ export function detectLocale(opts?: { lang?: string; cwd?: string }): Locale {
5
+ // 1. CLI --lang flag
6
+ if (opts?.lang) {
7
+ const normalized = normalizeLocale(opts.lang)
8
+ if (normalized) return normalized as Locale
9
+ }
10
+
11
+ // 2. LANG / LC_ALL env vars
12
+ const langEnv = process.env.LC_ALL || process.env.LANG || ''
13
+ const envLocale = parseLangEnv(langEnv)
14
+ if (envLocale) return envLocale
15
+
16
+ // 3. OS detection
17
+ const osLocale = detectOSLocale()
18
+ if (osLocale) return osLocale
19
+
20
+ // 4. Fallback
21
+ return 'en-US'
22
+ }
23
+
24
+ function normalizeLocale(raw: string): string | null {
25
+ const lower = raw.toLowerCase().replace('_', '-')
26
+ if (lower.startsWith('zh')) return 'zh-CN'
27
+ if (lower.startsWith('en')) return 'en-US'
28
+ return null
29
+ }
30
+
31
+ function parseLangEnv(env: string): Locale | null {
32
+ if (!env || env === 'C' || env === 'POSIX') return null
33
+ return normalizeLocale(env) as Locale | null
34
+ }
35
+
36
+ function detectOSLocale(): Locale | null {
37
+ try {
38
+ if (process.platform === 'darwin') {
39
+ const out = execSync('defaults read -g AppleLocale 2>/dev/null', {
40
+ encoding: 'utf-8',
41
+ timeout: 1000,
42
+ }).trim()
43
+ return normalizeLocale(out) as Locale | null
44
+ }
45
+ if (process.platform === 'win32') {
46
+ // Use Intl as fallback — the kernel32 approach is too complex for startup
47
+ return normalizeLocale(Intl.DateTimeFormat().resolvedOptions().locale) as Locale | null
48
+ }
49
+ // Linux: try LANG env one more time, then Intl
50
+ return normalizeLocale(Intl.DateTimeFormat().resolvedOptions().locale) as Locale | null
51
+ } catch {
52
+ return null
53
+ }
54
+ }