get user language

Workarounds and usability notes.

get user language

Postby John Robin Dove » Fri Apr 16, 2021 10:30 am

Hi Clifton,

In my program I distinguish between English GB and English US. The problem is window.navigator.language doesn't help much because it is the default language used when the browser was installed! Users can install and use other languages and these are in window.navigator.languages[0] etc. but there no way of telling which one is being used as far as I can tell. At the moment all I can get is fr So I assume the other langauges that I use will be en de es it. Apart from English there is no problem because I can test for these codes even if the complete codes are different like es-AR for example. Could you check what your browsers return please? If it is en-US my problem is solved. If not, I shall just have to ask the user to choose.

Regarding my previous post the password field is now functioning correctly but I cannot get the browsers to ask to save the password. I am quite sure that in the past this was not a problem. I remember creating a password field and as soon as it was used the browser responded by asking if the password should be saved. I have found a lot of stuff about this on Stack Overflow but it's all about forms and submit buttons that I am not using at the moment.

John
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: get user language

Postby Clifton » Fri Apr 16, 2021 11:20 am

window.navigator.language returns "en-US"

I believe the browser will only ask for password if the password is submitted to an online resource via a server side script like php. In addition, the user has to be directed to another page once they enter the password. The reason why a <form> wrapper works is because when a form is submitted, the information is sent to a server and page redirection ususally occurs.
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: get user language

Postby John Robin Dove » Sat Apr 17, 2021 5:09 am

Hi Clifton,
Thanks for your reply.

I will be able to handle US English with en-US.

I can't solve the prompt to save password problem. I have tried many examples of login forms provided by W3 Schools and others. Their examples all trigger the ask to save function. So I think whatever does it must be triggered by the php not the javascript. I have not been able to find a php example. I have made systems that use forms and work but they don't cause the browser to ask to save. For example https://www.mediacours.com/programs/dati/login.html
username: ARG1-1 password mB4tUvx3

My php code is
<?php
if (isset($_POST['username']) ) {
$username = $_POST['username'];
}

if (isset($_POST['password']) ) {
$password = $_POST['password'];
}
// The line below would be replaced with code to search in a MYSQL database
if ($username == 'ARG1-1' and $password == 'mB4tUvx3')
{
header('Location: ../in/');
}
else
{
header('Location: login.html');
}
?>


but there must be something missing.
John
UPDATE
It works! :D I have just discovered that it works on my Chrome browser. I have spent the whole morning testing on my Firefox browser. Of course it never asked to save the password because I have configured to never save anything (for testing purposes). You live and learn!
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron