@gonzui/claude-task-manager
Version:
Task management extension for Claude Code with archiving and history
194 lines • 6.37 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.I18n = void 0;
const fs = __importStar(require("fs-extra"));
const path = __importStar(require("path"));
class I18n {
constructor() {
this.messages = {};
this.currentLang = 'en';
this.initialized = false;
// In production, locales are in src/locales relative to package root
// In development, they are in src/locales relative to src
const isProd = __dirname.includes('dist');
this.localesDir = isProd
? path.join(__dirname, '../../src/locales')
: path.join(__dirname, '../locales');
}
static getInstance() {
if (!I18n.instance) {
I18n.instance = new I18n();
}
return I18n.instance;
}
async init(lang) {
if (lang) {
this.currentLang = lang;
}
await this.loadMessages();
this.initialized = true;
}
/**
* Synchronous initialization.
* Needed so command descriptions are localized in --help, which commander
* builds at module load time before any async preAction hook runs.
*/
initSync(lang) {
if (lang) {
this.currentLang = lang;
}
this.loadMessagesSync();
this.initialized = true;
}
async loadMessages() {
const lang = this.currentLang;
const filePath = path.join(this.localesDir, `${lang}.json`);
try {
const messages = await fs.readJson(filePath);
// Another init()/setLanguage() may have switched languages while this
// file was being read; a stale load must not clobber the newer messages.
if (this.currentLang === lang) {
this.messages = messages;
}
}
catch (error) {
if (this.currentLang !== lang) {
return;
}
// Fallback to English if language file not found
if (lang !== 'en') {
this.currentLang = 'en';
await this.loadMessages();
}
else {
throw new Error(`Failed to load language file: ${filePath}`);
}
}
}
loadMessagesSync() {
const filePath = path.join(this.localesDir, `${this.currentLang}.json`);
try {
this.messages = fs.readJsonSync(filePath);
}
catch (error) {
// Fallback to English if language file not found
if (this.currentLang !== 'en') {
this.currentLang = 'en';
this.loadMessagesSync();
}
else {
throw new Error(`Failed to load language file: ${filePath}`);
}
}
}
async setLanguage(lang) {
this.currentLang = lang;
await this.loadMessages();
}
getLanguage() {
return this.currentLang;
}
t(key, params) {
const keys = key.split('.');
let value = this.messages;
for (const k of keys) {
if (value && typeof value === 'object' && k in value) {
value = value[k];
}
else {
return key; // Return key if translation not found
}
}
if (typeof value !== 'string') {
return key;
}
// Replace parameters
let result = value;
if (params) {
Object.entries(params).forEach(([paramKey, paramValue]) => {
result = result.replace(new RegExp(`{{${paramKey}}}`, 'g'), String(paramValue));
});
}
return result;
}
// Get all messages for a specific namespace
getNamespace(namespace) {
const keys = namespace.split('.');
let value = this.messages;
for (const k of keys) {
if (value && typeof value === 'object' && k in value) {
value = value[k];
}
else {
return {};
}
}
if (typeof value === 'string') {
return {};
}
return value;
}
// Format priority labels based on language
formatPriority(priority) {
if (this.currentLang === 'ja') {
const priorityMap = {
'high': '高',
'medium': '中',
'low': '低'
};
return priorityMap[priority] || priority;
}
return priority;
}
// Get available languages
async getAvailableLanguages() {
try {
const files = await fs.readdir(this.localesDir);
return files
.filter(file => file.endsWith('.json'))
.map(file => file.replace('.json', ''));
}
catch {
return ['en'];
}
}
// Check if i18n is initialized
isInitialized() {
return this.initialized;
}
}
exports.I18n = I18n;
//# sourceMappingURL=i18n.js.map