Skip to content

Commit

Permalink
Add explicit toggle for using custom translation template, which shou…
Browse files Browse the repository at this point in the history
…ld assist in implementing automatic yarn/mojmap I18n templating in the future
  • Loading branch information
Moulberry committed May 5, 2024
1 parent 97988d6 commit b3b5fcf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/main/kotlin/MinecraftConfigurable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import com.intellij.ui.dsl.builder.bindItem
import com.intellij.ui.dsl.builder.bindSelected
import com.intellij.ui.dsl.builder.bindText
import com.intellij.ui.dsl.builder.panel
import com.intellij.ui.dsl.builder.selected
import com.intellij.ui.layout.ComponentPredicate
import com.intellij.util.IconUtil
import javax.swing.JComponent
import org.jetbrains.annotations.Nls
Expand Down Expand Up @@ -97,8 +99,17 @@ class MinecraftConfigurable : Configurable {
checkBox(MCDevBundle("minecraft.settings.translation.force_json_translation_file"))
.bindSelected(settings::isForceJsonTranslationFile)
}
row(MCDevBundle("minecraft.settings.translation.convert_to_translation_template")) {

lateinit var property: ComponentPredicate
row {
val checkBox = checkBox(MCDevBundle("minecraft.settings.translation.use_custom_convert_template"))
.bindSelected(settings::isUseCustomConvertToTranslationTemplate)
property = checkBox.selected
}

row {
textField().bindText(settings::convertToTranslationTemplate)
.enabledIf(property)
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/MinecraftSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class MinecraftSettings : PersistentStateComponent<MinecraftSettings.State> {
var isShadowAnnotationsSameLine: Boolean = true,

var isForceJsonTranslationFile: Boolean = false,
var isUseCustomConvertToTranslationTemplate: Boolean = false,
var convertToTranslationTemplate: String = "net.minecraft.client.resources.I18n.format(\"\$key\")",
)

Expand Down Expand Up @@ -95,6 +96,12 @@ class MinecraftSettings : PersistentStateComponent<MinecraftSettings.State> {
state.isForceJsonTranslationFile = forceJsonTranslationFile
}

var isUseCustomConvertToTranslationTemplate: Boolean
get() = state.isUseCustomConvertToTranslationTemplate
set(useCustomConvertToTranslationTemplate) {
state.isUseCustomConvertToTranslationTemplate = useCustomConvertToTranslationTemplate
}

var convertToTranslationTemplate: String
get() = state.convertToTranslationTemplate
set(convertToTranslationTemplate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ class ConvertToTranslationIntention : PsiElementBaseIntentionAction() {
val psi = PsiDocumentManager.getInstance(project).getPsiFile(editor.document) ?: return
psi.runWriteAction {
val expression = JavaPsiFacade.getElementFactory(project).createExpressionFromText(
MinecraftSettings.instance.convertToTranslationTemplate.replace("\$key", key),
if (MinecraftSettings.instance.isUseCustomConvertToTranslationTemplate) {
MinecraftSettings.instance.convertToTranslationTemplate.replace("\$key", key)
} else {
"net.minecraft.client.resources.I18n.format(\"$key\")"
},
element.context,
)
if (psi.language === JavaLanguage.INSTANCE) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/messages/MinecraftDevelopment.properties
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,5 @@ minecraft.settings.chat_color_underline_style=Chat color underline style:
minecraft.settings.mixin=Mixin
minecraft.settings.mixin.shadow_annotation_same_line=@Shadow annotations on same line
minecraft.setting.translation=Translation
minecraft.settings.translation.force_json_translation_file=Force JSON Translation File (1.13+)
minecraft.settings.translation.convert_to_translation_template=Template for Convert Literal To Translation
minecraft.settings.translation.force_json_translation_file=Force JSON translation file (1.13+)
minecraft.settings.translation.use_custom_convert_template=Use custom template for convert literal to translation

0 comments on commit b3b5fcf

Please sign in to comment.