{"id":16785067,"url":"https://github.com/imod/resource-bundle-gen","last_synced_at":"2025-09-29T08:13:57.598Z","repository":{"id":54196352,"uuid":"343190944","full_name":"imod/resource-bundle-gen","owner":"imod","description":"A small Java Annotation Processor (JSR-269) to generate a class to ease the access to resource bundles.","archived":false,"fork":false,"pushed_at":"2021-03-08T20:47:31.000Z","size":63,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-28T09:06:37.038Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imod.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-28T19:09:35.000Z","updated_at":"2021-03-08T20:59:57.000Z","dependencies_parsed_at":"2022-08-13T09:00:20.745Z","dependency_job_id":null,"html_url":"https://github.com/imod/resource-bundle-gen","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/imod/resource-bundle-gen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imod%2Fresource-bundle-gen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imod%2Fresource-bundle-gen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imod%2Fresource-bundle-gen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imod%2Fresource-bundle-gen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imod","download_url":"https://codeload.github.com/imod/resource-bundle-gen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imod%2Fresource-bundle-gen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277483740,"owners_count":25825665,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-29T02:00:09.175Z","response_time":84,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T08:08:05.720Z","updated_at":"2025-09-29T08:13:57.561Z","avatar_url":"https://github.com/imod.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ResourceBundle Processor\n\nResourceBundle Processor is a small Java Annotation Processor (JSR-269) generating a class to ease the access to java resource bundles.\n\n## What does it do?\n\nThe processor will generate a class with a method for each key in the given resource bundle. If the message contains placeholders, the method will have arguments to pass the values for each argument. The final message will be formated with a `java.text.MessageFormat`.\n\ne.g.\n\n`say.hi=Hello {0} {1}` will generate the following method signature:\n\n```java\npublic String sayHi(Locale locale, String arg0, String arg1)\n```\n\n_Note:_ Per default, the 'default bundle' file will be used to determine all the available keys and messages.\nIf the 'default bundle' does not hold all the messages which should be made available within the final class,\nyou can define all the files which should be used to find keys and messages in `filesToAnalyse` of `@ResourceBundle` (see \u003c\u003cConfiguration\u003e\u003e).\n\n## Advantages\n\n- No message/bundle keys distributed all over the source code.\n- Have the compiler check the number of arguments passed to `MessageFormat.format(..)`.\n- Source of the generated class is available and you can step through with any debugger.\n\n## Named arguments\n\nThe type field of the `@ResourceBundle`-annotation can be used to instruct the generator to support named arguments.\n\ne.g.\n\nAnnotation: `@ResourceBundle(bundle = \"mybundle\", type = COMMONS_TEXT)`\n\nBundle content: `say.by=By {firstName} {lastName}`\n\nwill generate the following method signature:\n\n```java\npublic String sayBy(Locale locale, String firstName, String lastName)\n```\n\nIn this case, the generated class will depend on `org.apache.commons.text.StringSubstitutor` of `commons-text`, therefore you need to add the following dependency to you project:\n\n```xml\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003eorg.apache.commons\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003ecommons-text\u003c/artifactId\u003e\n\t\t\t\u003cversion\u003e1.9\u003c/version\u003e\n\t\t\u003c/dependency\u003e\n```\n\n## Example\n\nTake the following resource bundle file (`ch/fortysix/test/messages.properties`):\n\n```txt\nsomekey=Some text\nsay.hi=Hello {0}\nsay_by=By {0} {1}\n```\n\nAnnotating a class with `@ResourceBundle` e.g.:\n\n```java\n@ResourceBundle(bundle = \"ch.fortysix.test.messages\", suffix = \"Messages\")\npublic class Application {\n}\n```\n\nWill generate this:\n\n```java\npublic class ApplicationMessages {\n\n    private static final class Holder {\n      private static final String BUNDLE_NAME = \"ch.fortysix.test.messages\";\n      private Map\u003cLocale, ResourceBundle\u003e bundles = new ConcurrentHashMap\u003c\u003e();\n\n      public ResourceBundle getBundle(Locale locale) {\n        return bundles.computeIfAbsent(locale, l -\u003e ResourceBundle.getBundle(BUNDLE_NAME, l));\n      }\n    }\n\n    private Holder holder = new Holder();\n\n    public String somekey(Locale locale) {\n      try {\n        return holder.getBundle(locale).getString(\"somekey\");\n      } catch (MissingResourceException e) {\n        return \"[somekey]\";\n      }\n    }\n\n    public String sayHi(Locale locale, String arg1) {\n      try {\n        String messagePattern = holder.getBundle(locale).getString(\"say.hi\");\n        return MessageFormat.format(messagePattern, arg1);\n      } catch (MissingResourceException e) {\n        return \"[say.hi]\";\n      }\n    }\n\n    public String sayBy(Locale locale, String arg1, String arg2) {\n      try {\n        String messagePattern = holder.getBundle(locale).getString(\"say_by\");\n        return MessageFormat.format(messagePattern, arg1, arg2);\n      } catch (MissingResourceException e) {\n        return \"[say_by]\";\n      }\n    }\n}\n```\n\n## Configuration\n\n### Annotation\n\n`@ResourceBundle` takes the following properties\n\n|=======================\n|  property |  default | description\n| bundle | | The name of the resource bundle. If the (properties) files are located within a package, you need to define the qualified name, but without the extension. e.g. `ch.fortysix.test.mybundle`\n| type  | JDK | - `JDK`: Generates the implementation based on the Java JDK only, no other dependencies are needed at runtime. Note: this implementation can not ensure the order of the arguments passed to MessageFormat is correct.\n\n- `COMMONS_TEXT`: Generates the implementation based on apache commons-text, supporting named arguments within the message. If you choose this type, you also need to add org.apache.commons:commons-text as a dependency to your project.\n| suffix | Bundle | The suffix to be added to the generated class. Base name is the name of the class this annotation is set on.\n| filesToAnalyse |   | Per default, the default bundle file will be used to determine all the available keys and messages. If the default bundle does not hold all the messages which should be made available within the final class, you can add all the files which should be used to find keys and messages here.\n|=======================\n\n### Dependency\n\nTo get `@ResourceBundle` available during compilation, you need add the dependency to `ch.fortysix:resource-bundle-annotation`. This is dependency is not required a runtime.\n\n```xml\n\t\t\u003cdependency\u003e\n\t\t\t\u003cartifactId\u003eresource-bundle-annotation\u003c/artifactId\u003e\n\t\t\t\u003cgroupId\u003ech.fortysix\u003c/groupId\u003e\n\t\t\t\u003cversion\u003e${latest.version}\u003c/version\u003e\n\t\t\t\u003coptional\u003etrue\u003c/optional\u003e\n\t\t\u003c/dependency\u003e\n```\n\n### Processor\n\nTo make the annotation processor/code generation work, you need to extend the compiler configuration:\n\n```xml\n\u003cplugin\u003e\n    \u003cgroupId\u003eorg.apache.maven.plugins\u003c/groupId\u003e\n    \u003cartifactId\u003emaven-compiler-plugin\u003c/artifactId\u003e\n    \u003cversion\u003e${maven-compiler-plugin.version}\u003c/version\u003e\n    \u003cconfiguration\u003e\n        \u003csource\u003e${jdk.version}\u003c/source\u003e\n        \u003ctarget\u003e${jdk.version}\u003c/target\u003e\n        \u003cannotationProcessorPaths\u003e\n            \u003cpath\u003e\n                \u003cgroupId\u003ech.fortysix\u003c/groupId\u003e\n                \u003cartifactId\u003eresource-bundle-processor\u003c/artifactId\u003e\n                \u003cversion\u003e${latest.version}\u003c/version\u003e\n            \u003c/path\u003e\n        \u003c/annotationProcessorPaths\u003e\n    \u003c/configuration\u003e\n\u003c/plugin\u003e\n```\n\n## Limitations\n\n- A annotation processor is only  triggered in case a java file changes, but the resource bundles actually are `properties`-files (XML is currenlty not supported),\ntherefore a compilation of the java class annotated with `@ResourceBundle` might need to be triggered in case the bunlde file changes.\ne.g. `mvn clean compile`\n- The current version only supports resource bundles in the form of properties files (no XML).\n\n## Alternatives\n\n- http://cal10n.qos.ch Compiler Assisted Localization, abbreviated as CAL10N (pronounced as \"calion\") is a java library for writing localized (internationalized) messages using resource bundles you are already familiar with, but with much greater comfort.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimod%2Fresource-bundle-gen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimod%2Fresource-bundle-gen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimod%2Fresource-bundle-gen/lists"}