umbraco-community / umbraco-analytics

Google Analytics for the Umbraco CMS
40 stars 31 forks source link

Dynamic handling of languages #4

Closed BatJan closed 9 years ago

BatJan commented 10 years ago

I noticed in the install code that the section is being added in the en.xml. It would be nice if it could be possible to update all translations somehow...not saying you need to know each language but at least just update it so people will see the english terms...it's still better than being faced with [SectionName]...I'll be happy to provide a danish translation btw. :)

warrenbuckley commented 9 years ago

This is progress @BatJan with the help of @bjarnef

warrenbuckley commented 9 years ago

@bjarnef have we localized all the things? Or do we still need to work on other items, if so can we create a specific issue or issue/s so they don't get overlooked or forgotten.

bjarnef commented 9 years ago

@warrenbuckley yes, almost.. the most important stuff for editor. One thing missing is the remote azure page mentioned here: https://github.com/warrenbuckley/Analytics/pull/18 .. it is this page: http://analytics-oauth.azurewebsites.net/callback/OAuth.aspx .. maybe we could send the locale/lang as a querystring. Furthermore the datepickers are not localized yet - but I think we can use moment.js to handle the different dateformat based on locale: http://momentjs.com/

But it is not critical it isn't translated yet.. it can wait for later.

abjerner commented 9 years ago

I have access to the repository for the OAuth site, so I can look into that tonight. Do we have any translations for that? I can probably dig something up for the Danish translations, but not much more...

bjarnef commented 9 years ago

@abjerner that would be great. Maybe a locale/lang parameter can be added to the url, when the user click on the button that opens the new browser window. I think the localizationService in the controller have a key you can use.

I think we should just ship with Danish and English, then people can always do their own translations or send a PR for other languages. There are a few lines of text, but not much. If you can translate that, I only think there are datepickers left (date format and translations) + a few labels on the axis in Chart.js, the Google Chart for countries and some values returned in the tables like (not set), mobile etc. But it is minor things and don't have to be included in this release (and I am not sure if those axis label etc. in the Charts is possible to translate at the moment).

abjerner commented 9 years ago

I can't find a way in localizationService to see the culture, so I've used UmbracoContext.Security.CurrentUser.Language in C# instead. It only returns da instead of da-DK, which would be preferred.

Most texts in the login dialog are now translated to Danish (I skipped some of the error messages for now).

The authentication site has its own private repository (currently only Warren and I have access to it), so it is currently not possible to make pull requests.

bjarnef commented 9 years ago

Okay, I thought about if the localizationService could send the locale as a parameter from this function in Settings.Controller.js

//Auth - Click
$scope.auth = function () {

    //Open a dialog window to oAuth
    //It will callback to http://analytics-oauth.azurewebsites.net/callback/oAuth.aspx?origin=http://localhost:62315
    window.open("/App_Plugins/analytics/backoffice/OAuth.aspx", "oAuthAnayltics", "location=0,status=0,width=600,height=600");
};

I looked a bit into the source code of Umbraco and found this: https://github.com/umbraco/Umbraco-CMS/blob/5b9a98ad6ae9e63322c26f7b162204e34f7fcb54/src/Umbraco.Web.UI.Client/src/views/common/dialogs/help.controller.js

So it seems you can use userService instead. if you inject userService to the controller

angular.module("umbraco").controller("Analytics.SettingsController",
    function ($scope, settingsResource, notificationsService, localizationService, navigationService, userService) {

and then later in auth function access current user, you can get the locale "da-DK" in my case with a User having Danish set to his language.

//Auth - Click
$scope.auth = function () {
    var rq = {};
    userService.getCurrentUser().then(function (user) {

        rq.usertype = user.userType;
        rq.lang = user.locale;

        console.log(rq);
    });

    //Open a dialog window to oAuth
    //It will callback to http://analytics-oauth.azurewebsites.net/callback/oAuth.aspx?origin=http://localhost:62315
    window.open("/App_Plugins/analytics/backoffice/OAuth.aspx", "oAuthAnayltics", "location=0,status=0,width=600,height=600");
};

the console now logs an object with userType and locale: Object {usertype: "admin", lang: "da-DK"}

or just save the user data in e.g. $scope.user

userService.getCurrentUser().then(function (user) {
    $scope.user = user;
    console.log($scope.user);
});
Object {email: "test@test.co.uk", locale: "da-DK", emailHash: "3bbf37f0bc4785ed290fd3582965d42e", userType: "admin", remainingAuthSeconds: 1165.9795592…}allowedSections: Array[8]0: "analytics"1: "content"2: "developer"3: "forms"4: "media"5: "member"6: "settings"7: "users"length: 8__proto__: Array[0]avatar: "//www.gravatar.com/avatar/3bbf37f0bc4785ed290fd3582965d42e?s=40&d=404"email: "test@test.co.uk"emailHash: "3bbf37f0bc4785ed290fd3582965d42e"id: 0locale: "da-DK"name: "Analytics for Umbraco"remainingAuthSeconds: 1163.9795592startContentId: -1startMediaId: -1userType: "admin"__proto__: Object
bjarnef commented 9 years ago

@abjerner you can probably get da-DK in C# by converting IUser.Language to CultureInfo https://twitter.com/Shazwazza/status/571104880623890432

https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/umbraco.businesslogic/ui.cs#L375

bjarnef commented 9 years ago

@abjerner In the remote page with the login button and this text:

"For at Analytics til Umbraco kan hente informationer om dine Google Analytics konti og profiler, skal du logge ind med Google for, at vi kan tilgå dine data.

Gå ikke panik - vi gemmer ikke dine loginoplysninger. Dit login sker direkte på Google's hjemmeside. Analytics for Umbraco har kun læseadgang til dine statistikker."

Maybe change the last "Analytics for Umbraco" to "Analytics til Umbraco".