mirror of
https://github.com/alibaba/p3c.git
synced 2025-10-15 15:40:26 +00:00
use Locale.default() for the initial language
This commit is contained in:
@@ -28,6 +28,7 @@ import org.eclipse.swt.graphics.Image
|
|||||||
import org.eclipse.swt.widgets.Display
|
import org.eclipse.swt.widgets.Display
|
||||||
import org.eclipse.ui.plugin.AbstractUIPlugin
|
import org.eclipse.ui.plugin.AbstractUIPlugin
|
||||||
import org.osgi.framework.BundleContext
|
import org.osgi.framework.BundleContext
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caikang
|
* @author caikang
|
||||||
@@ -72,20 +73,22 @@ class SmartfoxActivator : AbstractUIPlugin() {
|
|||||||
return image!!
|
return image!!
|
||||||
}
|
}
|
||||||
|
|
||||||
val locale: String get() {
|
val locale: String
|
||||||
val lang = preferenceStore.getString(localeKey)
|
get() {
|
||||||
return if (lang.isNullOrBlank()) {
|
val language = preferenceStore.getString(localeKey)
|
||||||
"zh"
|
if (language.isNullOrBlank()) {
|
||||||
} else {
|
val lang = Locale.getDefault().language
|
||||||
lang
|
return if (lang != Locale.ENGLISH.language && lang != Locale.CHINESE.language) {
|
||||||
|
Locale.CHINESE.language
|
||||||
|
} else Locale.getDefault().language
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return language
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleLocale() {
|
fun toggleLocale() {
|
||||||
preferenceStore.setValue(localeKey, when (locale) {
|
val lang = if (Locale.ENGLISH.language == locale) Locale.CHINESE.language else Locale.ENGLISH.language
|
||||||
"en" -> "zh"
|
preferenceStore.setValue(localeKey, lang)
|
||||||
else -> "en"
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRule(rule: String): Rule {
|
fun getRule(rule: String): Rule {
|
||||||
|
@@ -32,15 +32,12 @@ import com.intellij.openapi.project.DumbAware
|
|||||||
* @date 2017/06/20
|
* @date 2017/06/20
|
||||||
*/
|
*/
|
||||||
class SwitchLanguageAction : AnAction(), DumbAware {
|
class SwitchLanguageAction : AnAction(), DumbAware {
|
||||||
val p3cConfig = P3cConfig::class.java.getService()
|
private val p3cConfig = P3cConfig::class.java.getService()
|
||||||
|
|
||||||
val textKey = "com.alibaba.p3c.action.switch_language.text"
|
private val textKey = "com.alibaba.p3c.action.switch_language.text"
|
||||||
|
|
||||||
override fun actionPerformed(e: AnActionEvent) {
|
override fun actionPerformed(e: AnActionEvent) {
|
||||||
p3cConfig.locale = when (p3cConfig.locale) {
|
p3cConfig.toggleLanguage()
|
||||||
P3cConfig.localeZh -> P3cConfig.localeEn
|
|
||||||
else -> P3cConfig.localeZh
|
|
||||||
}
|
|
||||||
BalloonNotifications.showSuccessNotification(P3cBundle.getMessage("$textKey.success"), e.project,
|
BalloonNotifications.showSuccessNotification(P3cBundle.getMessage("$textKey.success"), e.project,
|
||||||
NotificationListener { notification, _ ->
|
NotificationListener { notification, _ ->
|
||||||
notification.expire()
|
notification.expire()
|
||||||
|
@@ -20,6 +20,7 @@ import com.intellij.openapi.components.State
|
|||||||
import com.intellij.openapi.components.Storage
|
import com.intellij.openapi.components.Storage
|
||||||
import com.intellij.openapi.components.StoragePathMacros
|
import com.intellij.openapi.components.StoragePathMacros
|
||||||
import com.intellij.util.xmlb.XmlSerializerUtil
|
import com.intellij.util.xmlb.XmlSerializerUtil
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -27,8 +28,7 @@ import com.intellij.util.xmlb.XmlSerializerUtil
|
|||||||
* @author caikang
|
* @author caikang
|
||||||
* @date 2017/06/19
|
* @date 2017/06/19
|
||||||
*/
|
*/
|
||||||
@State(name = "P3cConfig",
|
@State(name = "P3cConfig", storages = arrayOf(Storage(file = "${StoragePathMacros.APP_CONFIG}/smartfox/p3c.xml")))
|
||||||
storages = arrayOf(Storage(file = "${StoragePathMacros.APP_CONFIG}/smartfox/p3c.xml")))
|
|
||||||
class P3cConfig : PersistentStateComponent<P3cConfig> {
|
class P3cConfig : PersistentStateComponent<P3cConfig> {
|
||||||
var astCacheTime = 1000L
|
var astCacheTime = 1000L
|
||||||
var astCacheEnable = true
|
var astCacheEnable = true
|
||||||
@@ -38,7 +38,21 @@ class P3cConfig : PersistentStateComponent<P3cConfig> {
|
|||||||
|
|
||||||
var analysisBeforeCheckin = false
|
var analysisBeforeCheckin = false
|
||||||
|
|
||||||
var locale = localeZh
|
var locale: String = ""
|
||||||
|
get() {
|
||||||
|
if (field.isEmpty()) {
|
||||||
|
val lang = Locale.getDefault().language
|
||||||
|
return if (lang != Locale.ENGLISH.language && lang != Locale.CHINESE.language) {
|
||||||
|
Locale.CHINESE.language
|
||||||
|
} else Locale.getDefault().language
|
||||||
|
}
|
||||||
|
|
||||||
|
return field
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toggleLanguage() {
|
||||||
|
locale = if (localeEn == locale) localeZh else localeEn
|
||||||
|
}
|
||||||
|
|
||||||
override fun getState(): P3cConfig {
|
override fun getState(): P3cConfig {
|
||||||
return this
|
return this
|
||||||
@@ -51,8 +65,9 @@ class P3cConfig : PersistentStateComponent<P3cConfig> {
|
|||||||
XmlSerializerUtil.copyBean(state, this)
|
XmlSerializerUtil.copyBean(state, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val localeEn = "en"
|
val localeEn = Locale.ENGLISH.language!!
|
||||||
val localeZh = "zh"
|
val localeZh = Locale.CHINESE.language!!
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -29,7 +29,7 @@ import java.util.ResourceBundle
|
|||||||
* @date 2017/06/20
|
* @date 2017/06/20
|
||||||
*/
|
*/
|
||||||
object P3cBundle {
|
object P3cBundle {
|
||||||
val p3cConfig = P3cConfig::class.java.getService()
|
private val p3cConfig = P3cConfig::class.java.getService()
|
||||||
private val resourceBundle = ResourceBundle.getBundle("messages.P3cBundle",
|
private val resourceBundle = ResourceBundle.getBundle("messages.P3cBundle",
|
||||||
Locale(p3cConfig.locale), I18nResources.XmlControl())
|
Locale(p3cConfig.locale), I18nResources.XmlControl())
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user