Skip to content

Commit

Permalink
[styled-components] localization of StyledComponentsConfigurable
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 5acfe089d5625feb928f231dabe77abb8d720acd
  • Loading branch information
vepanimas authored and intellij-monorepo-bot committed Jan 20, 2023
1 parent 3a4f769 commit 24824e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import com.intellij.lang.javascript.JavascriptLanguage
import com.intellij.lang.javascript.refactoring.JSNamesValidation
import com.intellij.openapi.editor.event.DocumentEvent
import com.intellij.openapi.editor.event.DocumentListener
import com.intellij.openapi.fileTypes.PlainTextFileType
import com.intellij.openapi.fileTypes.PlainTextLanguage
import com.intellij.openapi.options.SearchableConfigurable
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.ComponentValidator
import com.intellij.openapi.ui.LabeledComponent
import com.intellij.openapi.ui.ValidationInfo
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.NlsContexts
import com.intellij.ui.EditorTextField
import com.intellij.ui.ToolbarDecorator
import com.intellij.ui.table.JBTable
Expand All @@ -30,11 +31,10 @@ class StyledComponentsConfigurable(private val project: Project) : SearchableCon
private val disposable = Disposer.newDisposable()

private fun createPrefixesField() = object : JBListTable(JBTable(tagsModel), disposable) {
override fun getRowRenderer(p0: Int): JBTableRowRenderer = object : EditorTextFieldJBTableRowRenderer(project,
PlainTextFileType.INSTANCE,
disposable) {
override fun getText(p0: JTable?, index: Int): String = tagsModel.myTags[index]
}
override fun getRowRenderer(p0: Int): JBTableRowRenderer =
object : EditorTextFieldJBTableRowRenderer(project, PlainTextLanguage.INSTANCE, disposable) {
override fun getText(p0: JTable?, index: Int): String = tagsModel.myTags[index]
}

override fun getRowEditor(p0: Int): JBTableRowEditor = object : JBTableRowEditor() {
override fun getValue(): JBTableRow = JBTableRow { (getComponent(0) as EditorTextField).text }
Expand All @@ -55,21 +55,22 @@ class StyledComponentsConfigurable(private val project: Project) : SearchableCon
override fun getFocusableComponents(): Array<JComponent> = arrayOf(preferredFocusedComponent)
override fun getPreferredFocusedComponent(): JComponent = getComponent(0) as JComponent

fun getErrorText(value: String?): String? {
fun getErrorText(value: String?): @NlsContexts.DialogMessage String? {
val trimmed = value?.trim() ?: ""
val names = trimmed.split(".")
if (trimmed.isBlank() || names.isEmpty()) {
return "Value is empty"
return StyledComponentsBundle.message("styled.components.configurable.error.value.is.empty")
}
return names.foldIndexed<String, String?>(null) { index, previous, string ->
if (previous != null) {
@Suppress("HardCodedStringLiteral")
previous
}
else if (index == 0 && !LanguageNamesValidation.INSTANCE.forLanguage(JavascriptLanguage.INSTANCE).isIdentifier(string, project)) {
"'$string' is not a valid JavaScript identifier"
StyledComponentsBundle.message("styled.components.configurable.not.valid.identifier", string)
}
else if (!JSNamesValidation.isIdentifierName(string)) {
"'$string' is not a valid property name"
StyledComponentsBundle.message("styled.components.configurable.not.valid.property.name", string)
}
else {
null
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/messages/StyledComponentsBundle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
styled.components.configurable.title=Styled Components
styled.components.configurable.label.tag.prefixes=Additional template tag prefixes:
styled.components.configurable.error.value.is.empty=Value is empty
styled.components.configurable.not.valid.identifier=''{0}'' is not a valid JavaScript identifier
styled.components.configurable.not.valid.property.name=''{0}'' is not a valid property name

0 comments on commit 24824e2

Please sign in to comment.