@lokascript/framework 2.10.0 → 2.11.1

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.js CHANGED
@@ -2893,14 +2893,26 @@ var MultilingualDSLImpl = class {
2893
2893
  }
2894
2894
  translate(input, fromLanguage, toLanguage) {
2895
2895
  if (isExplicitSyntax(input)) return input;
2896
- for (const language of [fromLanguage, toLanguage]) {
2897
- if (!this.profileProvider.getProfile(language)) {
2898
- throw new Error(
2899
- `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'.`
2900
- );
2896
+ let node;
2897
+ try {
2898
+ node = this.parseWithConfidence(input, fromLanguage).node;
2899
+ } catch (parseError) {
2900
+ if (this.hasGrammarProfile(fromLanguage) && this.hasGrammarProfile(toLanguage)) {
2901
+ return this.transformer.transform(input, fromLanguage, toLanguage);
2901
2902
  }
2903
+ throw parseError;
2904
+ }
2905
+ const rendered = this.registry.getSupportedLanguages().includes(toLanguage) ? this.render(node, toLanguage) : null;
2906
+ if (rendered != null) return rendered;
2907
+ if (this.hasGrammarProfile(fromLanguage) && this.hasGrammarProfile(toLanguage)) {
2908
+ return this.transformer.transform(input, fromLanguage, toLanguage);
2902
2909
  }
2903
- return this.transformer.transform(input, fromLanguage, toLanguage);
2910
+ throw new Error(
2911
+ `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).`
2912
+ );
2913
+ }
2914
+ hasGrammarProfile(language) {
2915
+ return this.profileProvider.getProfile(language) != null;
2904
2916
  }
2905
2917
  compile(input, language) {
2906
2918
  if (!this.codeGenerator) {