Hi I get text from database with http.get .How to get with browser detection ? How to use if clause ? I don't want to use translate.toogle()
var mainCtrl = function ($scope, $http, $sce, $location,$timeout,$routeParams, toastr) { $scope.showPage = false; $timeout(function(){ $scope.showPage = true; },2000); $scope.trustedHtml = function (plainText) { return $sce.trustAsHtml(plainText); } $http.get('admin/api/?s=getAbout').success( ##### if browser En_en function(r){ $scope.about = r.text_en; ##### if browser De_de function(r){ $scope.about = r.text_de; } ); };
This should be solved by checking for WebSocket support, and applying a polyfill if there is no native support. This should be done with a library like Modernizr. That being said, you can easily create service that would return the browser.
Open the browser settings, and in the advanced section scroll down to find Languages . Open Language and Input Settings and add the language or language+region choice you want from the list available. Order the resulting list so that it is in descending order of preference. You don't need to restart Chrome.
Detecting browser preference is the most common and most effective way used by websites to detect your preferred language automatically. Very simply put, when you install and set up the browser on your device, you choose the language that you want to use.
You can get the browser language using navigator.language
:
var lang = $window.navigator.language || $window.navigator.userLanguage; if (lang === 'en-US') { console.log("language is english"); }
navigator.languages ? navigator.languages[0] : (navigator.language || navigator.userLanguage)
is the best way.
ref: JavaScript for detecting browser language preference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With