i18n: changing enum to... class static fields?

Hello

I am involved in a project where I had some enums. This enum has benefited from the latest versions, so I got something very standard as:
public enum MyEnum{
   ONE("one"),
   TWO("two");

   private final String literal;

   private MyEnum(String literal){
      this.literal = literal;
   }

   @Override
   public String toString(){
      return literal;
   }
}
I have not only one, but several of them. My problem is that I might need to translate these literals in several languages and I'm not sure which is the best way to do it. I thought about having several singletons in my main class. Once we know the language, I'd get these names from a .properties file and initialize these singletons, but I really think that sounds bad. Who is the best practice in this scenario?

Maybe a singleton class that contains a map with (key, translation) and I ask for these names to the object?

Thank you!
Luis

ldepablo wrote:
OK, so I'll give it another chance ;-)

Let's say I have i18n-IZE the app, so I put the enum value TWO that gets the value "zwei" of my numbers_de.properties. Where should I save these values?

You could look for a group of resources, each time, or you could store in a card in or outside the enum to be retrieved by a suitable research method.

I would say in a list/map in some singleton component in my factory class.

I don't know enough about your needs or design to comment on where the map should be live. I don't know why you consider the list, since you probably want to get these things by keys. In other words, you do not use TWO as the number 2, but rather as a constant to get you the key to look up the word "two". You will also have an enum value DOG, with a literal "dog", so that you can find "hund" (or other) in German, "perro" in Spanish and "inu" in Japanese, Yes? For a list wouldn't you do much good for looking for these things.

Or am I missing something?

Later, I read the word "zwei" in the source, and want to know what value corresponds to "zwei", so I search for "zwei" in my list/map, get his position, which would be the 'second' and that way I'll know the result's 2.

Why do you need to know the position? That makes sense to me, especially in view of the fact that the cards have indices.

But if you need a means of correspondence between the word 'zwei' return to his forefinger--or its value enum TWO - key then just build two maps, one for each direction.

Tags: Java

Similar Questions

  • Cannot change the homepage. The field is grey than above it.

    It started with the last Firefox update a couple of days. The home page has been hijacked by Yahoo, and I can't change that. The two fields in the Start Option page are grayed out and cannot accept the changes. Restoration of Firefox had no effect. Also:

    Despite the fact that I chose to avoid pop-ups, they reappear at a brisk pace, especially of nature that I am not interested to be disturbed.

    Help, please.

    Y at - it all prefs on the topic: config page that were locked in the status column?

    You can click the report header to sort by that column.

  • changing enum values

    1. I want to do an enum with the strings [] being the value of the file (a text file containing "option 1, option 2, option 3...").
    I already have a vi that gets the file and gives a table with options, but it seems that I can't change propety [enum] channels off within the program.

    I thought to use a second vi that, during race will open my main vi, change the [] of the enum strings, run the main program and stop, but that seems a lot of trouble for something that is supposed to be simple.

    is there an easier way to do it?

    attached are the vi, a snip of the vi, as well as a list of example.

    2. once I have this work - I have a tab control where many of the tabs using enums with the same list. what I do need to create a property for each enum node or is there a better way?

    Thank you!

    You cannot change the enum values, time of execution. Have you tried to use a menu ring or a ring of text (see attachment).

    Little more in detail here to try to change enums

    http://digital.NI.com/public.nsf/allkb/24C62D0FFA55132C8625694B006FCF17

    Edit: What Paul says!

  • How to change the color of form fields

    I don't know how to change the color of form fields. They default to gray, but I don't know how to make a different color.

    Gray does not match the color scheme of my landing page!

    Thank you!

    I think you have two options when you are working on a landing page with an embedded format:

    • You can change the background color of the entire form field set by selecting the shape, and then clicking on the Toolbox. In the window that opens go to the second (on a paint brush icon) and select the background color you want.
    • You can change the background color of the actual fields in the form by adding CSS styles. Select the Toolbox, go to the last tab (Tools Extract page) and in the middle of this window, you will see "head | CSS | JS"- select this average CSS tab and enter the style code to get the color you want. Here is an example of code you can put in it. Note that #000000 is the color code for black. Here is more information about the code: css - background in the input fields and text color? - stack overflow

  • I have Acrobat Pro 10, when I installed the CD player, it has affected the way I was able to move text boxes when I create a form of gall, he has also affected my ability to release and change the properties of the fields /, I'm I suspect m

    I have Acrobat Pro 10, when I installed the CD player, it has affected the way I was able to move text boxes when I create a form of gall, he has also affected my ability to release and change the properties of the fields /, I'm I suspect my off lucky cat Adobe support will not help , nor a cure to.  Is there a place to find updates to Acrobat 10, if I uninstall my current program?  I still have my original CD and paperwork.  Adobe acknowledge that they have created this problem.   I worked very intensively with Acrobat Pro 10 on the form for a non-profit, I do part, and it happened immediately after that I was testing a form I created in Acrobat 10 to test with CD player. Windows 7 operating system

    This is usually due to the function 'Snap to Grid' is enabled. It can be accidentally activated via the keyboard, so this may have been what happened.

  • Hi, is it possible to change the security class for folders that contain data forms?

    Hello

    We would like to change the class of security for a folder that contains the data forms in our application.

    This should be done on two occasions during our monthly closing.

    When I create a new folder I can assign the class of security to the folder. But how it works for an existing folder?

    Thank you very much

    Björn

    HFM 11.1.2.1

    Hello

    To answer your question, there is no way to change the safety classes existing folder with the existing versions of HFM. We have already asked DEV as an improvement. The only solution is to remove the existing form folder and then re-create.

    Kind regards

    Madhu.

  • Change the value of a field when the value of another field changes.

    I have a level of order form with a number of areas where the quantity (number) is typed in they are labeled qty1, 2 and so on.

    Some of the items on the order form attract additional fixed a load which is shown in a separate field call it addcharge.

    If qty1 has a number entered it attracts an additional cost and the addcharge field changes the value of zero to say 1

    If 2 has a number entered without extra charge applies

    If 3 is a number entered without supplement applies

    If qty4 has a number it attracts an additional cost and the addcharge field changes the value of zero to say 1 or if the previous qty1 has already changed the addcharge to 1 field, remains at 1.

    If qty5 has a number entered it attracts an additional cost and the addcharge field changes the value of zero to say 1 or if the previous qty1 and qty4 has already changed the addcharge to 1 field, it remains 1


    It seems to me that some "if else" enabling javascript is necessary in the sense of "If qty1 field is greater at 0 addcharge field is 1"and I guess the script must be placed in each field which attracts addcharge.»»»


    Can anyone help with the script please.


    Thanks Eric

    Please sign the right answer. Thank you.

  • Change the properties of several fields

    I need to change the properties of corn (i.e., the number) of several fields when I pass the selection and then right-click, Format tab is not there. Help, please.

    Hi rednexhex,

    It is not possible to change the format of several fields at the same time

    You will need to manually change each field.

    Kind regards

    Rave

  • Check box to change the value of the field and reveal hidden text

    Hello

    I need to change a value in a field when you press a checkbox

    the default value can be $ 10 in 'formfield1 '.

    But when the checbox is checked, the value of 'formfield1' must spend $ 8

    I also need a reval text function in "textfield2' of the text hidden to visible.

    Is it still possible to combine in a box?

    I found a code on the forum and changed it, but it does not work as expected, it affects the field, it shouldn't and it behaves a bit funny, here is the code to calculate.

    I also tried to change the value of Off to On, but who has not reversed the procedure than I hoped.

    Well its a start, maybe someone can understand a give me help on the way?

    ________________________________

    custom for the discount calculation

    var nDiscount = 2;

    name of the Sub total field

    var cSubTotal = "formfield1";

    name of the non-Discount checkbox

    var cbNonDiscount = "CheckBox1";

    default value for the non-Discount

    Event.Value = 10;

    see if the purchase is with discount or not non-Discount

    If (this.getField ("cbNonDiscount") .value == 'Off') {}

    Event.Value = this.getField ("cSubTotal") .value - nDiscount;

    }

    put an end to a custom calculation

    Ah, if you want the calculation to take place when the box is checked, use this:

    If (this.getField (cbNonDiscount) .value! = "Off") {}

    Instead:

    If (this.getField ("cbNonDiscount") .value == 'Off') {}

  • How can I change the text of the field mouseover popup?

    How can I change the text of the field mouseover popup? I can't find it anywhere? A help for popup search comes up with nothing.

    Thank you for the help on this.

    If you are looking to update the tool tip you do this in the palette "accessibility". You can use the window > accessibility or SHIFT + F6 to open it. Hope that helps.

  • How to change the value of a field?

    Hello

    I am a beginner in the report and I try to change the format of a field trigger value
    by the PL/SQL code editor

    is this possible? How can I identify my field (: MONCHAMP: does not work = newvalue)

    @rosagio

    Hello

    You cannot change the value of a column, but the field display values. Do it with the built-in SRW. SET_FIELD...
    Take a look at http://www.oracle.com/webapps/online-help/reports/10.1.2?navId=3&navSetId=_&vtTopicFile=htmlhelp_rwbuild_hs/rwrefex/plsql/builtins/examps/srw_examples.htm
    It is built-ins different depending on the data type. The object_id is 0 every time for the current object.

    concerning
    Rainer

  • It is a way to force capitalize an entry in a field in a web form. What would be hard-code? I don't want to change the CSS class.

    This code would be:

    < label for = "CAT_Custom_162533" > TYPE IN YOUR FASCIA NAME below: < / label > < input type = "text" placeholder = "for example. Incredible juice Joe"class ="cat_textbox"id ="CAT_Custom_162533"name ="CAT_Custom_162533"maxlength ="4000"/ >

    You would do this with javascript.

  • Two quick questions (hopefully) - right way to dynamically change the CSS class and put of Splash screen implemented

    Couple of quick questions have left me speechless!

    So, it seems obvious that many JavaFX applications want to dynamically change the CSS styles.  Is the best way to do it through la.getStyleClass () .add ("classname") < node >?  The underlying data structure is a list of observable.  So let's say we have 5 styles that simply to change the fill color of a circle of 5 different colors, respectively.  So if I have a condition in which I want to dynamically apply 1 of these 5 styles, as I do now it's by setting all 5 styles as a string in a list by using a static initializer, then I call < node > .getStyleClass () .removeAll (list), then getStyleClass () .add ("classname").  I do this to avoid adding again and still the same style and inflate the underlying list.  What is the right way to manage dynamic CSS styles?

    Finally a very simple I think.  So I know there's a little differently to implement a splash screen.  My app has certainly got bigger in the last few months of development and I noticed there are about a 5 second delay between when I run the application when I see the main stage.  I was thinking what a splash screen would be nice to fill that time.  I had no time to prototype using a Preloader and I fear that using another, early stage start-up again would be too long of a delay.  "I actually thought that using the Nice and simple JVM argument" - splash: image name > "would be simple, easy and effective.  Unfortunately when I try to do, the splash screen appears but never goes away.  Anyone know what is happening with this?

    Your mechanism to manage the css style classes is a good approach; I've used several times. I wonder why the style classes have been implemented as a list, instead of a game, but there may be cases of good use for the use of a list.

    In some cases you can also consider using CSS PsuedoClasses, which were presented in JavaFX 8. Here is a little easier to use, especially if you have two options. But a use case might look like:

    public class Message {
        public enum Status { NORMAL, WARNING, CRITICAL }
    
        private final ObjectProperty status = new SimpleObjectProperty<>(Status.NORMAL);
        private final StringProperty message = new SimpleStringProperty();
    
        // constructor, getters, setters, and property accessors....
    }
    
    public Label createLabel(Message message) {
        PseudoClass warning = PseudoClass.getPseudoClass("warning");
        PseudoClass critical = PseudoClass.getPseudoClass("critical");
    
        Label label = new Label();
        label.textProperty().bind(message.messageProperty());
        message.statusProperty().addListener((obs, oldStatus, newStatus) -> {
            label.pseudoClassStateChanged(warning, newStatus == Message.Status.WARNING);
            label.pseudoClassStateChanged(critical, newStatus == Message.Status.CRITICAL);
        }
        return label ;
    }
    

    And then your css looks like

    .label:warning {
        -fx-text-fill: orange ;
    }
    .label:critical {
        -fx-text-fill: red ;
    }
    
  • JavaScript question - accept user input and use them in other areas with case changed (i.e. in a field to uppercase and the other as capatilsed each)

    Hi ther,.

    Ive been away from Livecucle for quite awhile and I lost a handle on coding.

    I am tyring to get the data from that paid to be repeated also in two other areas with different formatting (in capital letters and capatilise each word)

    Therefore, if the user enters "james smith michael" in a named filed - say - fullanme - she could also be replicated in a fullnameCaps file - changed to uppercase in this area (i.e: JAMES MICHAEL SMITH) and - class fullnameCapsEach get out of James Michael Smith

    the other fields will be just hidden.

    I remembered hot change the entry to the ceilings in the entry field - xfa.event.change = xfa.event.change.toUpperCase () - but that only works in the entry field of course.

    I tried to set the fullnameCaps and the fullnameCapsEach to equal the rawvalue of the entry fullanme field and put the code of change in them - but that doesn't seem to be the answer!

    Someone out there you have nay of ideas?

    see you soon

    Hello

    Try this solution in the event of change of your input field:

    var str = xfa.event.newText, capsAll, capsFirst;
    
      capsAll = str.toUpperCase();
      capsFirst = str.toLowerCase().replace(/([^a-z]|^)([a-z])(?=[a-z]{1})/g, function(_, g1, g2) {
        return g1 + g2.toUpperCase();
        });
    
    fullnameCaps.rawValue = capsAll;
    fullnameCapsEach.rawValue = capsFirst;
    
  • How to change the size of any field?

    Hello, I'm developing a CLDC Application on JDE 4.7, and I have a problem while I create a custom field (no field, NullField, VertivalFieldManaher, LabalField, etc.). I do an override of the method getPreferredWidth() or getPreferredHeight() to set the new height and width of my field, but when printing, a string to the console in the painting of the method, I don't see that this painting of the method is executed in a cycle.

    This an expmple of code:

    public class ExpanderField extends VerticalFieldManager {
        public int getPreferredHeight() {
            return 200;
        }
    
        public int getPreferredWidth() {
            return 200;
        }
    
        protected void subpaint(Graphics graphics) {
            //super.paint(graphics);
            System.out.println("Paint Method Executed");
        }
    
        protected void sublayout(int width, int height) {
            super.sublayout(getPreferredWidth(), getPreferredHeight());
            super.setExtent(getPreferredWidth(), getPreferredHeight());
            System.out.println("layout executed...");
        }
    
    }// ExpanderField class
    

    In this example, the string "Painting executed method" is printed permanently. I don't know why the method of painting is executed all the time.

    Anyone know what is happen?

    I think I found the answer. In another class of my project, I put the setPosition() sentence; in the method object of a VerticalFieldManager and this sentence call once again, the paint so this method to cycle, and all fields checked for this VerticalFieldManager are painted, once again what is run the paint method in the VerticalFieldManager.

    But I have a question for developers RIM...

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/...

    Why in the code example above, you use the setPosition() phrases; and getManager () .invalidate (); within the method object?, this sentences call the Paint method constantly and never stop, it is not an effective way to program an application.

Maybe you are looking for