setting the langauge for translation inside a formula?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamie
    Senior Member
    • Aug 2025
    • 226

    #1

    setting the langauge for translation inside a formula?

    when runing a formula i need to translate some strings based on a language variable but it doesn't tell me how to in the documentation


    if there any way to set this?
  • yuri
    EspoCRM product developer
    • Mar 2014
    • 9639

    #2
    Not possible, will be implemented in v9.4 I think.

    Meanwhile, I suggest creating a custom function.

    Comment

    • jamie
      Senior Member
      • Aug 2025
      • 226

      #3
      Originally posted by yuri
      Not possible, will be implemented in v9.4 I think.

      Meanwhile, I suggest creating a custom function.
      ahh good stuff thats not tooo far away, btw i wasn't too sure what scope meant in there, it was linked to an entity?

      Comment

      • jamie
        Senior Member
        • Aug 2025
        • 226

        #4
        if any one is in a hurry here is what i did to get this working

        Code:
        <?php
        namespace Espo\Custom\FormulaFunctions;
        use Espo\Core\Formula\ArgumentList;
        use Espo\Core\Formula\Functions\BaseFunction;
        use Espo\Core\Formula\Processor;
        use Espo\Core\Utils\Language\LanguageFactory;
        
        class translateTo extends BaseFunction
        {
        public function __construct(
        Processor $processor,
        private LanguageFactory $languageFactory,
        ) {
        $this->processor = $processor;
        }
        public function process(ArgumentList $args)
        {
        if (count($args) < 1) {
        $this->throwTooFewArguments(2);
        }
        $args = $this->evaluate($args);
        $language = $this->languageFactory->create($args[1]);
        return $language->translate($args[0], 'snipits', 'snipits');
        }
        }
        and then add it in here custom/Espo/Custom/Resources/metadata/app/formula.json and clear cache

        Comment

        Working...