U4-11372 - Make history section on Info tab translatable

Created by Anders Brohus 27 May 2018, 17:59:03 Updated by Sebastiaan Janssen 28 Jun 2018, 17:47:16

Tags: Up For Grabs PR

The new info tab looks and works great! :) But accidently i was looking at one of our client's website and saw that it was in english even through the backend language was danish, so i began looking for the lines in the xml file containing all the translations, but i could not find them, so i created an issue on Our, where @JanSkovgaard told me that it was hardcoded.

So that is what this is all about making these lines of text translateable :)

2 Attachments

Comments

Sebastiaan Janssen 28 May 2018, 09:04:48

I think the problem is that everybody can add audit events with any text they want (from their custom code).

All of the messages you see like "performed by user" are just spread out over the codebase (see screenshot). I don't think it's feasible to create all of these as translatable items, they're not actually labels like the other UI events, they are really just messages that come from the log.

That said, it could definitely be good to normalize the messages that the core puts in there and replace them with translations from the xml files instead.

We would love some help with that, here's an example of localizing something:

Services.TextService.Localize("speechBubbles/operationSavedHeader")

If you have variables you need to pass into the translation file, you can do it something like this:

Services.TextService.Localize("speechBubbles/operationSavedHeader", myVariable, secondVariable)

The xml would look something like this:

First variable: %1% - and second variable: %2%


Anders Brohus 28 May 2018, 10:36:48

Nice thanks @sebastiaan :)

If it's possible i would like to try make this PR :)

It will be a fun way to start digging deeper into the Core :D


Sebastiaan Janssen 28 May 2018, 10:42:02

Awesome, go for it!


Anders Brohus 28 May 2018, 10:44:03

Thanks will do tonight :)


Anders Bjerner 28 May 2018, 18:06:55

@andersbrohus I'm not 100% sure about this, as I haven't actually played around with this part of Umbraco before. But I would do something like the following:

  1. The ServiceContext class is responsible for initializing the various services - eg. the content service is initialized here: https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Core/Services/ServiceContext.cs#L240

From what I can tell, this is the only place that the ContentService class is initialized.

  1. The localized text service is initialized a bit longer up the file, and is available through _localizedTextService.Value. I would pass that as an additional parameter to the content service.

  2. Add that additional parameter (of the type ILocalizedTextService) to the constructor of the ContentService class. You'll find the implementation here: https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Core/Services/ContentService.cs#L38

  3. Store the localized text service in a private field within the ContentService class so that you can access it from methods within the class

  4. I haven't looked at the other services, but it should be somewhat the same

  5. Test the changes

  6. Create pull request

  7. Klap dig selv på skulderen ;)

Also, don't be afraid to create the pull request. Even if you're not totally sure, the HQ is very helpful getting it merged, and comes with pointers for improving the code if necessary ;)


Anders Brohus 28 May 2018, 18:19:09

Thanks alot @abjerner now i have work to do for the rest of the night :D


Anders Brohus 28 May 2018, 19:54:02

Woohoo first PR is here! :)

https://github.com/umbraco/Umbraco-CMS/pull/2650

Keep in mind that this is still work in progress as i still need to make some textes translateable :)


Anders Brohus 30 May 2018, 18:43:41

So i guess this is done :)

Have worked for two days now and it's really good! :)


Priority: Normal

Type: Bug

State: Fixed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted: Pull request

Affected versions:

Due in version: 7.12.0

Sprint:

Story Points:

Cycle: