UNPKG

@mdfriday/foundry

Version:

The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.

168 lines 4.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Language = void 0; /** * CollatorWrapper - wrapper for Collator to match Go interface */ class CollatorWrapper { constructor(collator) { this.collator = collator; } compare(a, b) { return this.collator.compare(a, b); } } /** * Language - TypeScript equivalent of Go's Language entity * Handles multi-language functionality */ class Language { constructor(langSvc) { this.collator = null; this.langSvc = langSvc; this.currentLocation = 'UTC'; this.currentLanguage = ''; } /** * Get current language index * TypeScript equivalent of CurrentLanguageIndex method from Go */ currentLanguageIndex() { try { return this.langSvc.getLanguageIndex(this.currentLanguage); } catch (error) { throw new Error(`language "${this.currentLanguage}" not found`); } } /** * Setup language configuration * TypeScript equivalent of setup method from Go */ async setup() { // TODO: make it configurable from config timeZone field this.currentLocation = 'UTC'; } /** * Get all available languages * TypeScript equivalent of Languages method from Go */ languages() { const langs = []; for (const lang of this.langSvc.languageKeys()) { const language = new Language(this.langSvc); language.currentLocation = this.currentLocation; language.currentLanguage = lang; language.collator = this.collator; langs.push(language); } return langs; } /** * Get collator for string comparison * TypeScript equivalent of Collator method from Go */ getCollator() { if (!this.collator) { try { // Use Intl.Collator for locale-aware string comparison const intlCollator = new Intl.Collator(this.currentLanguage || 'en'); this.collator = new CollatorWrapper({ compare: (a, b) => intlCollator.compare(a, b) }); } catch (error) { // Fallback to English collator const intlCollator = new Intl.Collator('en'); this.collator = new CollatorWrapper({ compare: (a, b) => intlCollator.compare(a, b) }); } } return this.collator; } /** * Get current location (timezone) * TypeScript equivalent of Location method from Go */ location() { return this.currentLocation; } /** * Check if site has multiple languages * TypeScript equivalent of isMultipleLanguage method from Go */ isMultipleLanguage() { return this.langSvc.languageKeys().length > 1; } /** * Get language prefix for URLs * TypeScript equivalent of LanguagePrefix method from Go */ languagePrefix() { if (this.currentLanguage === this.langSvc.defaultLanguage()) { return ''; } return this.currentLanguage; } /** * Get current language code * TypeScript equivalent of Lang method from Go */ lang() { return this.currentLanguage; } get Lang() { return this.lang(); } /** * Get current language name * TypeScript equivalent of LanguageName method from Go */ languageName() { return this.langSvc.getLanguageName(this.currentLanguage); } /** * Get default language name * TypeScript equivalent of DefaultLanguageName method from Go */ defaultLanguageName() { return this.langSvc.getLanguageName(this.langSvc.defaultLanguage()); } /** * Get language code (alias for lang) * TypeScript equivalent of LanguageCode method from Go */ languageCode() { return this.currentLanguage; } get LanguageCode() { return this.languageCode(); } get LanguageDirection() { return "ltr"; // Default to left-to-right } /** * Get language direction * TypeScript equivalent of LanguageDirection method from Go */ languageDirection() { // TODO: Add RTL language detection logic // For now, default to left-to-right return 'ltr'; } setCurrentLanguage(lang) { this.currentLanguage = lang; } getCurrentLanguage() { return this.currentLanguage; } /** * Set current location/timezone */ setCurrentLocation(location) { this.currentLocation = location; } } exports.Language = Language; //# sourceMappingURL=language.js.map