I have some enums in my Typescript application and I use code similar to this to get the string value to display in the application:
enum Color{ RED, BLUE, GREEN};
document.write( "The string for Red is: " + Color[Color.RED] );
However, the string value is usually more along the lines of a database key or some other server related string rather than a nicely formatted string fit for display to the user. To get round this I want to load localised property files that use the string value of an enum to look up a nicely formatted string to display in the application. The file might look like this:
Color.properties:
RED=The color is red
BLUE=The color is blue
GREEN=The color is green
I am confident that I can load this file and parse the contents to populate some lookup for later display in the application but I am not sure about how to know which property file to load. For the following enums
Color
Shape
Animal
I will have the following property files:
Color.properties
Shape.properties
Animal.properties
My question is: Is there any way of getting the string "Color" from the run time javascript definition of Color? The Typescript code for Color gets transpiled into:
var Color;
(function (Color) {
Color[Color["RED"] = 0] = "RED";
Color[Color["BLUE"] = 1] = "BLUE";
Color[Color["GREEN"] = 2] = "GREEN";
})(Color || (Color = {}));
I don't think that I can get the String Color out of that in any easy way. I assume that I am just going to have to use switch expression to lookup the name of the file.