Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nyavro/i18nPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nyavro committed Aug 6, 2020
2 parents 81497d0 + d376045 commit 48f62cc
Show file tree
Hide file tree
Showing 21 changed files with 195 additions and 70 deletions.
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Intellij idea i18next support plugin

## Features
### Annotations
### Annotations

- Annotates correct i18n keys:

Expand All @@ -36,12 +36,31 @@ Intellij idea i18next support plugin
![Reference to plural value](docs/img/p5.png)


### Navigation
### Navigation

- I18nPlugin provides navigation from key to its declaration in Json resource

![Reference to plural value](docs/img/p6.png)
![Navigation from key to translation](docs/img/p6.png)

- and to partially resolved keys:

![Reference to plural value](docs/img/p7.png)
![Navigation from partially resolved](docs/img/p7.png)

### Hints

- In the case of a single translation matching to given key the translation displayed as a hint (Ctrl + hover):

![Single translatin hint](docs/gif/translation-as-hint.gif)

### Configuration options
(File->Tools->I18n plugin configuration)

- Default namespace

Configure up to 100 default namespace translation files.
Multiple default namespaces separated by comma, semicolon or whitespace:

first;second third,fourth

will resolve translations in files first.json, second.json, third.json, fourth.json

Binary file added docs/gif/translation-as-hint.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/simple/asset/en/sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"ROOT": {
"Key1": {
"key2": "value1174",
"key21": "value1174",
"key31": "vvv"
},
"Key41": "The answer is 41!"
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/src/Modules/Test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Test {
static render(unknownInCompileTime: string) {
const i18n = new I18n();

console.log('sample:ROOT.Key1.key2'); //Simple case resolved
console.log('sample:ROOT.Key1.key21'); //Simple case resolved
console.log('sample:missing.whole.composite.key'); //Unresolved whole key
console.log('sample:ROOT.missing.composite.key'); //Unresolved part of the key
console.log('MissingFile:Ex.Sub.Val'); //Unresolved File
Expand Down
18 changes: 9 additions & 9 deletions examples/vue-i18n-files-simple/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions examples/vue-i18n-js-config-simple/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ package com.eny.i18n.plugin.ide.completion

import com.eny.i18n.plugin.language.js.JsCallContext

/**
* Completion contributor for JS dialects
*/
class JsCompletionContributor: CompositeKeyCompletionContributor(JsCallContext())
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ package com.eny.i18n.plugin.ide.completion

import com.eny.i18n.plugin.language.php.PhpCallContext

/**
* PHP Completion contributor
*/
class PhpCompletionContributor: CompositeKeyCompletionContributor(PhpCallContext())
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ package com.eny.i18n.plugin.ide.completion

import com.eny.i18n.plugin.language.vue.VueCallContext

/**
* Completion contributor for Vue
*/
class VueCompletionContributor: CompositeKeyCompletionContributor(VueCallContext())
13 changes: 13 additions & 0 deletions src/main/kotlin/com/eny/i18n/plugin/ide/hint/HintProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.eny.i18n.plugin.ide.hint

import com.eny.i18n.plugin.utils.unQuote
import com.intellij.lang.documentation.DocumentationProvider
import com.intellij.psi.PsiElement

/**
* Shows key's translation as a hint.
* Works for very simple case only - when there is exactly one translation corresponding to key.
*/
class HintProvider : DocumentationProvider {
override fun getQuickNavigateInfo(element: PsiElement?, originalElement: PsiElement?): String? = element?.text?.unQuote()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ package com.eny.i18n.plugin.ide.references.code

import com.eny.i18n.plugin.language.js.JsReferenceAssistant

/**
* JS dialect reference contributor
*/
class JsReferenceContributor: ReferenceContributorBase(JsReferenceAssistant())
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ package com.eny.i18n.plugin.ide.references.code

import com.eny.i18n.plugin.language.php.PhpReferenceAssistant

/**
* PHP dialect reference contributor
*/
class PhpReferenceContributor: ReferenceContributorBase(PhpReferenceAssistant())
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ package com.eny.i18n.plugin.ide.references.code

import com.eny.i18n.plugin.language.vue.VueReferenceAssistant

/**
* Vue dialect reference contributor
*/
class VueReferenceContributor: ReferenceContributorBase(VueReferenceAssistant())
12 changes: 11 additions & 1 deletion src/main/kotlin/com/eny/i18n/plugin/ide/settings/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import com.eny.i18n.plugin.utils.whenMatches
import com.intellij.openapi.project.Project
import com.intellij.psi.search.GlobalSearchScope

/**
* Configuration holder
*/
data class Config (
val searchInProjectOnly: Boolean = true,
val nsSeparator: String = ":",
Expand All @@ -22,11 +25,18 @@ data class Config (
val yamlContentGenerationEnabled: Boolean = true
) {

private val MAX_DEFAULT_NAMESPACES = 100

/**
* Gets list of default namespaces
*/
fun defaultNamespaces(): List<String> =
defaultNs.whenMatches {it.isNotBlank()}.default(Config().defaultNs).split("[;|,\\s]".toRegex()).filter {it.isNotBlank()}
defaultNs
.whenMatches {it.isNotBlank()}
.default(Config().defaultNs)
.split("[;|,\\s]".toRegex())
.filter{it.isNotBlank()}
.take(MAX_DEFAULT_NAMESPACES)

/**
* Gets project's search scope
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/com/eny/i18n/plugin/ide/settings/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class Settings : PersistentStateComponent<Settings> {

internal var yamlContentGenerationEnabled = default.yamlContentGenerationEnabled

/**
* Returns plugin configuration
*/
fun config(): Config {
if (ApplicationManager.getApplication().isHeadlessEnvironment) {
synchronized(this) {
Expand Down
Loading

0 comments on commit 48f62cc

Please sign in to comment.