0

I have a AngularJS Application in different languages.

Now I want to preselect a language, when the user calls the site, with following string at the end: /en, /de, ...

Is this even possible in AngularJS? I also can use some other syntax, if this is needed.

Thank you very much!

2
  • 1
    you'll prob need to provide links/code though if you are looking for implementation suggestions Commented Dec 18, 2014 at 14:59
  • Thank you for your reply, atmd! That do you mean with links? I´m just looking for a way to "parse" the URL (read the params from URL) in a nice "AngularJS"-Way. :) Commented Dec 18, 2014 at 15:01

2 Answers 2

1

If you are wanting to get something from the url to run logic on (i.e. /de in the url) you can use the $location object

Angular location

If you are wanting dynamic urls so that things like /de, /fr, /es go to the same page/view, you'll need to use the $route object

Angular routes

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. $location works perfectly fine: $location.path() contains the String "/de" when I call my site via domain/#/de - thank you!
1

With the limited amount I could understand from your question..

var app=angular.module("angularapp",['ngRoute']);
app.config(['$routeProvider', function($routeProvider) {
$routeProvider
    .when('/',{
        redirectTo: '/en'
    })
    .when('/:language',{
        //do something
    });
}]);

you can then get access to {"language":"en"} object

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.