UNPKG

@osaedasia/oresume

Version:

A user-friendly library for generating complete Single Page Applications (SPAs)

59 lines (58 loc) 2.38 kB
import { Observable } from "../observer/Observable"; import { ISO639_1 } from "../../domain/definitions/types/Country"; import { LanguageService } from "../LanguageService"; /** * Manages localized resources for specific locale codes with reactive capabilities. * @template T Resource structure type extending Record<string, string>. * @template LSupported Supported language codes extending ISO639_1. */ export declare class LocalizedResource<T extends Record<string, string>, LSupported extends ISO639_1> { /** * Maps language codes to their corresponding resources. */ private readonly _resources; /** * Stores observable streams for resource properties. */ private readonly _generatedObservables; /** * Service handling language-specific operations. */ private readonly _languageService; /** * Dynamic mapping of resource properties to observable streams. */ private readonly _resourceProxy; /** * Creates a new LocalizedResource instance. * @param {LanguageService<LSupported>} languageService Service providing language-specific functionality. */ constructor(languageService: LanguageService<LSupported>); /** * Retrieves the resource proxy containing observable values. * @returns {Object} A proxy object mapping resource keys to their Observable streams. */ get res(): { [K in keyof T]: Observable<string>; }; /** * Associates a resource with a specific language code. * @param {LSupported} languageCode The language code for the resource. * @param {T} resource The resource object to be associated. */ addResource(languageCode: LSupported, resource: T): void; /** * Creates or retrieves an observable for the specified resource key. * @param {keyof T} key The resource key to observe. * @returns {Observable<string>} An observable stream for the specified key. */ private _getObservable; /** * Retrieves a localized value for a given key and language code. * Falls back to default language if the requested translation is unavailable. * @param {ISO639_1} code The language code to retrieve the value for. * @param {keyof T} key The resource key. * @returns {string} The localized value or an empty string if not found. */ private _getKeyValue; }