资源目录新建message文件夹
新建后会推荐你安装一个插件
用法可以封装一下
- package com.anguomob.anguo.utils
-
- import org.jetbrains.annotations.PropertyKey
- import java.text.MessageFormat
- import java.util.ResourceBundle
-
- object StringBundle {
- private val bundle = ResourceBundle.getBundle("message.strings")
-
- fun string(@PropertyKey(resourceBundle = "message.strings") key: String, vararg params: Any): String {
- val value = bundle.getString(key)
- return if (params.isNotEmpty()) {
- MessageFormat.format(value, *params)
- } else {
- value
- }
- }
- }
具体使用代码 修改hello的那个参数
- package com.anguomob.anguo.actions
-
- import com.anguomob.anguo.utils.StringBundle
- import com.intellij.notification.NotificationDisplayType
- import com.intellij.notification.NotificationGroup
- import com.intellij.openapi.actionSystem.AnAction
- import com.intellij.openapi.actionSystem.AnActionEvent
- import org.gradle.internal.impldep.org.joda.time.DateTime
-
- class HelloWordAction : AnAction() {
- override fun actionPerformed(event: AnActionEvent) {
- val notifacationGroup = NotificationGroup(
- "Anguo", NotificationDisplayType.BALLOON, true
- )
-
- notifacationGroup.createNotification(
- "Hello World", StringBundle.string("hello", DateTime.now().toString()), "你说不要自作自受自己创造伤悲,安果出来的插件才能有伤悲"
- ).notify(event.project)
- }
- }