Page 1 of 1

How to set the language using REST API

Posted: Wed Dec 27, 2017 8:32 am
by jemiris
Hi Support,

How to pass the language using REST API ?

Re: How to set the language using REST API

Posted: Wed Jan 03, 2018 1:47 am
by amosbatto
There is no REST endpoint to select the language. What do you need it for?

You can create a custom REST endpoint to set the language. For example to set the language to Spanish, you can use this code in your custom endpoint:
Code: Select all
$_SESSION['SYS_LANG'] = 'es';
 
I have created a plugin that you can use to test it:
(23 KiB) Downloaded 494 times
After you import and activate the plugin, you can call it as PUT http://{domain-or-ip}/api/1.0/{workspace}/extrarest/language/{lang}
where {lang} is a variable in the URL, such as:
http://example.com/api/1.0/workflow/ext ... anguage/es
http://example.com/api/1.0/workflow/ext ... uage/pt-BR

You can check the system language with the endpoint GET http://{domain-or-ip}/api/1.0/{workspace}/extrarest/language

Does that work for you?

Re: How to set the language using REST API

Posted: Sun Jan 07, 2018 1:38 am
by jemiris
Thank you for the great answer :) .

And one more clarification using rest api sample url :http://example.com/api/1.0/workflow/ext ... uage/pt-BR let's have. Can we set the session in rest api like this $_SESSION['SYS_LANG'] = $lang; will it work

Re: How to set the language using REST API

Posted: Tue Jan 09, 2018 1:29 am
by amosbatto
jemiris wrote:And one more clarification using rest api sample url :http://example.com/api/1.0/workflow/ext ... uage/pt-BR let's have. Can we set the session in rest api like this $_SESSION['SYS_LANG'] = $lang; will it work
The plugin I gave you has that code:
$_SESSION['SYS_LANG'] = $lang;
Here is relevant code:
Code: Select all
    /**
     * Set the login language in $_SESSION['SYS_LANG']
     * 
     * @url PUT /language/:lang
     * @access protected
     *
     * @param string $lang 
     * 
     * @author Amos Batto <amos@processmaker.com>
     * @copyright Public Domain
     */
    public function putSystemLanguage($lang)
    {  
        if (empty($lang) or empty(trim($lang))) {
           throw new Exception("System language cannot be empty.");
        }
        
        $_SESSION['SYS_LANG'] = $lang;
        
        return null;
    } 
    
    /**
     * Get the login language stored in $_SESSION['SYS_LANG']
     * 
     * @url GET /language
     * @access protected 
     * 
     * @author Amos Batto <amos@processmaker.com>
     * @copyright Public Domain
     */
    public function getSystemLanguage($lang)
    {  
        if (!isset($_SESSION['SYS_LANG'])) {
           throw new Exception("System language for login session does not exist.");
        }
                
        return $_SESSION['SYS_LANG'];
    }
After you import the plugin, look at the code in the file workflow/engine/plugins/extraRest/src/Services/Api/ExtraRest/Extra.php

Re: How to set the language using REST API

Posted: Fri Jan 19, 2018 1:12 am
by jemiris
Hi support,

Thanks a lot for the great answer :lol: