Skip to content
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ Command line application for [POEditor](https://poeditor.com).
$ [sudo] gem install poeditor-cli
```

Install from given repo and branch:

```console
$ [sudo] gem specific_install https://github.com/splendo/poeditor-cli -b kotlin-plurals
```

## Usage

A single command will do almost everything for you.
Expand Down Expand Up @@ -121,6 +127,30 @@ path_replace:
en: myapp/src/main/res/values/strings.xml
```

* Multiplatform project

For Kotlin and [Kaluga](https://github.com/splendo/kaluga)

```yaml
api_key: $POEDITOR_API_KEY
project_id: $POEDITOR_PROJECT_ID
type: kotlin_strings
languages: [en]

header: "package my.project.models"
path: 'shared/src/commonMain/kotlin/my/project/models/Strings.kt'
path_plural: 'shared/src/commonMain/kotlin/my/project/models/Plurals.kt'
```

Where header is your package for generated objects.

Usage:

```kotlin
val myString = Strings.myAwesomeString
val myPlural = Plurals.myAwesomePlural(someIntValue)
```

* Projects using gettext

```yaml
Expand Down
7 changes: 5 additions & 2 deletions lib/poeditor/commands/pull_command.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module POEditor
class PullCommand
def run(argv)
UI.puts "Reading configuration"
configuration = get_configuration(argv)
UI.puts configuration
client = POEditor::Core.new(configuration)
client.pull()
end
Expand Down Expand Up @@ -43,10 +41,15 @@ def get_configuration(argv)
type: get_or_raise(yaml, "type"),
tags: yaml["tags"],
filters: yaml["filters"],
header: yaml["header"],
languages: get_or_raise(yaml, "languages"),
language_alias: yaml["language_alias"],
path: get_or_raise(yaml, "path"),
path_plural: yaml["path_plural"],
path_replace: yaml["path_replace"],
context_path: yaml["context_path"],
context_path_plural: yaml["context_path_plural"],
context_path_replace: yaml["context_path_replace"]
)
end

Expand Down
33 changes: 30 additions & 3 deletions lib/poeditor/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class Configuration

# @return [Array<String>] Filters by 'translated', 'untranslated', 'fuzzy', 'not_fuzzy', 'automatic', 'not_automatic', 'proofread', 'not_proofread' (optional)
attr_accessor :filters

# @return [Hash{Sting => String}] Header (optional)
attr_accessor :header

# @return [Array<String>] The languages codes
attr_accessor :languages
Expand All @@ -25,23 +28,42 @@ class Configuration
# @return [String] The path template
attr_accessor :path

# @return [String] The plural path template
attr_accessor :path_plural

# @return [Hash{Sting => String}] The path replacements
attr_accessor :path_replace

def initialize(api_key:, project_id:, type:, tags:nil,
filters:nil, languages:, language_alias:nil,
path:, path_replace:nil)
# @return [String] The context path template
attr_accessor :context_path

# @return [String] The plural context path template
attr_accessor :context_path_plural

# @return [Hash{Sting => String}] The context path replacements
attr_accessor :context_path_replace

def initialize(api_key:, project_id:, type:, tags:nil, filters:nil,
header:nil, languages:, language_alias:nil,
path:, path_plural: nil, path_replace:nil,
context_path:nil, context_path_plural:nil, context_path_replace:nil)
@api_key = from_env(api_key)
@project_id = from_env(project_id.to_s)
@type = type
@tags = tags || []
@filters = filters || []
@header = header

@languages = languages
@language_alias = language_alias || {}

@path = path
@path_plural = path_plural || {}
@path_replace = path_replace || {}

@context_path = context_path
@context_path_plural = context_path_plural || {}
@context_path_replace = context_path_replace || {}
end

def from_env(value)
Expand All @@ -58,10 +80,15 @@ def to_s
"type" => self.type,
"tags" => self.tags,
"filters" => self.filters,
"header" => self.header,
"languages" => self.languages,
"language_alias" => self.language_alias,
"path" => self.path,
"path_plural" => self.path_plaural,
"path_replace" => self.path_replace,
"context_path" => self.context_path,
"context_path_plural" => self.context_path_plural,
"context_path_replace" => self.context_path_replace,
}
YAML.dump(values)[4..-2]
.each_line
Expand Down
Loading