How to change language in template

Hello,

I would like to ask if it’s possible to change the language with a custom button ?
If possible, the change should be in the following file : layout.user.php

Thanks

I don’t think this is possible. What is your use case?

I want to use it in my custom header.
I tried something like this but I’m running into error 405 :

<form id="language" method="post">
    <button style="background: 0; border: 0" type="submit">
	    English
	</button>
	<input type="hidden" name="lang" value="en_GB">
</form>

I also tried with method GET but the language doesn’t change

This is not supported. Nextcloud has a setting for the user language already. You don’t have to build your own.

There is no workaround ?

What would be the point if it’s creates something that is already there?

I’m sorry but this section of the forum is about Nextcloud development and Nextcloud app development. I don’t see any aspect where a custom language button would make sense in this context.

I don’t want to create it, I want to move it into my custom template in the header. I want to use only 2 language so I don’t need the list, I want to be able to change the lang on a single button

Ok, I see, so some special development it is to customize Nextcloud to your requirements.

I can’t help with that.

I did it successfully. Here is how I made it.

Add this js code into a custom js template file :

jQuery( document ).ready(function() {
    function updateLanguage() {
        if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
            OC.PasswordConfirmation.requirePasswordConfirmation(updateLanguage);
            return;
        }
        var selectedLang = $("#languageinputCustom").val(),
		user = OC.getCurrentUser();
        $.ajax({
	    	url: OC.linkToOCS('cloud/users', 2) + user['uid'],
	        method: 'PUT',
            data: {
	            key: 'language',
                value: selectedLang
	        },
            success: function() {
                location.reload();
	        },
            fail: function() {
                OC.Notification.showTemporary(t('settings', 'An error occurred while changing your language. Please reload the page and try again.'));
            }
        });
    }
    $("#languageChangeCustom").on( "click", function() {
        updateLanguage()
    });
});

On the template side (for eg: layout.user.php) :

<?php
if($l->t('lang') == "fr"){
?>
<img id="languageChangeCustom" style="width: 50px; height: auto;" src="<?php print_unescaped(image_path($_['appid'], 'english.png')); ?>" alt="Lang EN">
<input id="languageinputCustom" type="hidden" name="lang" value="en_GB">
<?php
}else{
?>
<img id="languageChangeCustom" style="width: 50px; height: auto;" src="<?php print_unescaped(image_path($_['appid'], 'spanish.png')); ?>" alt="Lang ES">
<input id="languageinputCustom" type="hidden" name="lang" value="es">
<?php
}
?>