0

I posted a comment to the following thread asking for clarification on an answer, and the author suggested I expand the comment into a formal question.

The response speaks to the benefits of using resources as a modular localization solution. My question is, what is the inherent benefit of using resource files (and a resx manager) versus an interface/class based solution. It seems to me that in a MVC/MVVM type design pattern, the view will be nearly exclusively variable references. If you create an interface for each view, you will have an instant understanding as to whether a view has been fully implemented for a language. This could be implemented as shown below:

Language File:

public interface IMyAppLogin
{
    string LoginPrompt { get; }
    string ForgotPWLabel { get; }
}

public class Eng : IMyAppLogin
{
    public string LoginPrompt => "Please Login";

    public string ForgotPWLabel => "Forgot your password?";
}

public class Portuguese : IMyAppLogin
{
    public string LoginPrompt =>  "Login por favor";

    public string ForgotPWLabel => "Não lembro o Senha?";
}

Model:

public class MyAppLoginModel
{
    IMyAppLogin Lang;
}

Controller:

 public class AController
{
    MyAppLoginModel m;
    public AController(string la)
    {
        switch(la)
        {
            case "pt": 
                m.Lang = new Portuguese();
                break;
            default:
                m.Lang = new Eng();
                break;
        }

    }

}

Finally your view would reference the model to fill in the text.

These language classes could be compartmentalized and made portable in their own Standard .Net Library. If you needed to send it to a translator, you could create an excel template to send externally, and then it would be trivial to create a script that would convert an excel generated .csv into the class format shown below.

Why is the resource method better than this method? Or maybe restated, which is the better method for attacking reusable localization?

tmptplayer
  • 434
  • 7
  • 18
  • Looks very-opinion based... Reimplementing language fallbacks, language discovery at runtime,... and inventing custom infrastructure is entertaining but it's up to you to decide which one suits *your project* better... Even whether duplication of text like "more" and "ok" across hundreds of view classes is personal choice... – Alexei Levenkov Nov 19 '19 at 01:35
  • Of course it's up to me, but I'm trying to learn best practice from the community. I'm ok accepting that the resource method is a best practice, but I'm trying to understand why. – tmptplayer Nov 19 '19 at 02:04
  • So... you tried to implement your solution for reasonably sized program/site (let's say at least 50 "views") and for reasonably set of languages (even starting with 10-15) - did you find any drawbacks? How it compares to the same approach with regular resx files? Asking "what's better" in generally not on-topic for SO, comparing libraries (which is the other thing you are essentially asking) is not on-topic either... Ideally you perform your own investigation and than come back to edit the question with concrete problems you need help with your approach... – Alexei Levenkov Nov 19 '19 at 02:31

0 Answers0