Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PropertyKey with compile time prefix value #10

Open
saylenty opened this issue Jan 26, 2019 · 0 comments
Open

PropertyKey with compile time prefix value #10

saylenty opened this issue Jan 26, 2019 · 0 comments

Comments

@saylenty
Copy link

saylenty commented Jan 26, 2019

Hello!

I'd like to use PropertyKey in some of my projects in order to control usages of l10n keys in compile time. The issue that I faced is that all my property keys is prefixed with "title" and "detail" values. So that when I create an object (that needs to be localized) I set only the error key without prefix. See the code below for clarification:

// imports omitted
public final class Error {
    private final String errorKey;
    public String getErrorKey() {
        return errorKey;
    }
    // would like to ability to set _prefix_ value(s)
    public Error(@PropertyKey(resourceBundle = "app", prefix={"title.", "detail."}) String errorKey) {
        this.errorKey = errorKey;
    }
}

public class ErrorHandler{
    // somewhere in errorHandler
    public void localizeError(Error error, ResourceBundle resourceBundle){
        // create prefixed keys
        String titleKey = "title." + error.getErrorKey();
        String detailKey = "detail." + error.getErrorKey();

        // localize the error
        String title = resourceBundle.getString(titleKey);
        String detail = resourceBundle.getString(detailKey);

        // print localized messages
        System.out.println("Localized error title is: " + title);
        System.out.println("Localized error detail is: " + detail);
    }
}

So, my questions are:

  1. Is it possible to get this functionality in the nearest feature? And could you suggest any workaround for now?
  2. Could I write my own annotation with such functionality? Probably in this case I'm supposed to enhance the IDEA inspections. I've never written customization (plugins or so) for IDEA and I'm afraid it would require a lot of work to implement my simple logic, isn't it?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant