Add operator function for resource bundle key access in MyBundle

This commit is contained in:
Jakub Chrzanowski
2026-05-04 10:25:36 +02:00
parent 65f5bd6d51
commit e566ce7752
4 changed files with 11 additions and 4 deletions

View File

@@ -4,6 +4,10 @@
## [Unreleased]
### Added
- Add operator function for resource bundle key access in `MyBundle`
### Changed
- Dependencies - upgrade `org.jetbrains.intellij.platform` to `2.16.0`

View File

@@ -9,6 +9,9 @@ private const val BUNDLE = "messages.MyBundle"
object MyBundle : DynamicBundle(BUNDLE) {
operator fun get(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
getMessage(key, *params)
@JvmStatic
fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
getMessage(key, *params)

View File

@@ -9,7 +9,7 @@ import org.jetbrains.plugins.template.MyBundle
class MyProjectService(project: Project) {
init {
thisLogger().info(MyBundle.message("projectService", project.name))
thisLogger().info(MyBundle["projectService", project.name])
thisLogger().warn("Don't forget to remove all non-needed sample code files with their corresponding registration entries in `plugin.xml`.")
}

View File

@@ -32,12 +32,12 @@ class MyToolWindowFactory : ToolWindowFactory {
private val service = toolWindow.project.service<MyProjectService>()
fun getContent() = JBPanel<JBPanel<*>>().apply {
val label = JBLabel(MyBundle.message("randomLabel", "?"))
val label = JBLabel(MyBundle["randomLabel", "?"])
add(label)
add(JButton(MyBundle.message("shuffle")).apply {
add(JButton(MyBundle["shuffle"]).apply {
addActionListener {
label.text = MyBundle.message("randomLabel", service.getRandomNumber())
label.text = MyBundle["randomLabel", service.getRandomNumber()]
}
})
}