loreline 0.8.1 → 0.9.0

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/js/loreline.d.ts CHANGED
@@ -270,6 +270,62 @@ export class Loreline {
270
270
  */
271
271
  static extractTranslations(script: Script): Translations;
272
272
 
273
+ /**
274
+ * Loads translations for a specific locale, walking the script's full import tree.
275
+ *
276
+ * For each file involved in the script (root + transitively imported), the
277
+ * corresponding translation file is looked up by inserting `.<locale>` before
278
+ * the extension (e.g. `characters.lor` → `characters.fr.lor`). Missing translation
279
+ * files are silently skipped. The returned map can be passed as
280
+ * `InterpreterOptions.translations` to `play()` or `resume()`.
281
+ *
282
+ * @param locale The locale code (e.g. `"fr"`)
283
+ * @param script The parsed source script (must have been parsed with a file path,
284
+ * or `filePath` must be provided)
285
+ * @param filePath Optional override for where to look for translation files
286
+ * (defaults to `script.filePath`). Can be a `.lor`/`.lor.txt` file
287
+ * path or a directory.
288
+ * @param handleFile File handler used to read translation files
289
+ * @param callback Called with the merged translations map. Required if `handleFile` is asynchronous.
290
+ * @returns The merged translations map (synchronously when `handleFile` is sync)
291
+ */
292
+ static loadLocale(
293
+ locale: string,
294
+ script: Script,
295
+ filePath?: string | null,
296
+ handleFile?: ImportsFileHandler,
297
+ callback?: (translations: Translations) => void
298
+ ): Translations | null;
299
+
300
+ /**
301
+ * Enable or disable runtime support for an alternate translation file format.
302
+ *
303
+ * By default only `.<locale>.lor` files are tried by `loadLocale`. Call
304
+ * this to opt in to additional formats:
305
+ * - `"po"` — GNU gettext PO (`.po`)
306
+ * - `"xliff"` — XLIFF 1.2 / 2.x (`.xliff`, `.xlf`)
307
+ * - `"csv"` — CSV / TSV (`.csv`, `.tsv`)
308
+ *
309
+ * Unknown names are accepted silently (forward-compat for future formats).
310
+ *
311
+ * @param name The format identifier (see above)
312
+ * @param enabled True to enable the format, false to disable
313
+ */
314
+ static translationFormat(name: string, enabled: boolean): void;
315
+
316
+ /**
317
+ * Returns the error from the most recent failed `parse()` or `loadLocale()`
318
+ * call, or `null` on success.
319
+ *
320
+ * In async mode (callback supplied) the callback fires with `null` on
321
+ * failure and this method tells you what went wrong. In sync mode the
322
+ * call throws, and this is set to the same error so it can be inspected
323
+ * after the catch.
324
+ *
325
+ * Not thread-safe — read immediately after the call returns.
326
+ */
327
+ static lastError(): Error | null;
328
+
273
329
  /**
274
330
  * Prints a parsed script back into Loreline source code.
275
331
  *
@@ -398,6 +454,15 @@ export class Interpreter {
398
454
  * @return The current node or null if no node is being executed
399
455
  */
400
456
  currentNode(): Node | null;
457
+
458
+ /**
459
+ * Returns the file path of the file containing the current node.
460
+ * Resolves through import chains relative to the given root file path.
461
+ *
462
+ * @param rootPath The file path of the root/main script
463
+ * @return The file path of the file containing the current node, or rootPath if in the root file
464
+ */
465
+ currentNodeFilePath(rootPath: string): string;
401
466
  }
402
467
 
403
468
  /**
@@ -483,6 +548,12 @@ export class Script extends Node {
483
548
  */
484
549
  body:Array<Node>;
485
550
 
551
+ /**
552
+ * The file path this script was parsed from.
553
+ * May be null if the script was parsed without a file path.
554
+ */
555
+ filePath: string | null;
556
+
486
557
  /**
487
558
  * Reconstructs a Script from a JSON representation.
488
559
  * @param json The JSON object (as returned by script.toJson())