@lokascript/framework 2.9.4 → 2.11.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/dist/index.cjs CHANGED
@@ -3029,14 +3029,26 @@ var MultilingualDSLImpl = class {
3029
3029
  }
3030
3030
  translate(input, fromLanguage, toLanguage) {
3031
3031
  if ((0, import_intent3.isExplicitSyntax)(input)) return input;
3032
- for (const language of [fromLanguage, toLanguage]) {
3033
- if (!this.profileProvider.getProfile(language)) {
3034
- throw new Error(
3035
- `translate() requires a grammar profile for language "${language}", but none is configured. Set 'grammarProfile' on the LanguageConfig for "${language}" in createMultilingualDSL() (parse/validate/compile do not need it), or inject a custom 'profileProvider'.`
3036
- );
3032
+ let node;
3033
+ try {
3034
+ node = this.parseWithConfidence(input, fromLanguage).node;
3035
+ } catch (parseError) {
3036
+ if (this.hasGrammarProfile(fromLanguage) && this.hasGrammarProfile(toLanguage)) {
3037
+ return this.transformer.transform(input, fromLanguage, toLanguage);
3037
3038
  }
3039
+ throw parseError;
3040
+ }
3041
+ const rendered = this.registry.getSupportedLanguages().includes(toLanguage) ? this.render(node, toLanguage) : null;
3042
+ if (rendered != null) return rendered;
3043
+ if (this.hasGrammarProfile(fromLanguage) && this.hasGrammarProfile(toLanguage)) {
3044
+ return this.transformer.transform(input, fromLanguage, toLanguage);
3038
3045
  }
3039
- return this.transformer.transform(input, fromLanguage, toLanguage);
3046
+ throw new Error(
3047
+ `translate() could not render action "${node.action}" in language "${toLanguage}": no custom renderer, domain renderer, or schema pattern covers it, and no grammar profile is configured for the transformer fallback. Either add "${toLanguage}" to the DSL's languages/renderer, or set 'grammarProfile' on its LanguageConfig in createMultilingualDSL() (parse/validate/compile do not need it).`
3048
+ );
3049
+ }
3050
+ hasGrammarProfile(language) {
3051
+ return this.profileProvider.getProfile(language) != null;
3040
3052
  }
3041
3053
  compile(input, language) {
3042
3054
  if (!this.codeGenerator) {