Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yonaskolb/stringly
Manage and generate localization files
https://github.com/yonaskolb/stringly
cli generator localization strings
Last synced: 23 days ago
JSON representation
Manage and generate localization files
- Host: GitHub
- URL: https://github.com/yonaskolb/stringly
- Owner: yonaskolb
- License: mit
- Created: 2019-10-17T05:33:29.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-26T15:08:19.000Z (about 3 years ago)
- Last Synced: 2024-03-14T15:49:04.805Z (8 months ago)
- Topics: cli, generator, localization, strings
- Language: Swift
- Homepage:
- Size: 86.9 KB
- Stars: 18
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Stringly
Stringly generates type safe localization files from a source `yaml`,`json`, or `toml` file. At the moment only outputs for Apple platforms are supported, but a generator for Android's R.strings is easy to add
- ✅ **Multi-language** support
- ✅ **Named placeholders**
- ✅ **Plural** support
- ✅ Compile safe **Swift** accessors## Usage
See help
```
stringly help
```
To generate all files in all languages
```
stringly generate Strings.yml
```
To generate a single file in a certain langage
```
stringly generate-file Strings.yml Strings.strings --language de
```## Installing
Make sure Xcode 13 is installed first.
### [Mint](https://github.com/yonaskolb/mint)
```sh
mint install yonaskolb/stringly
```### Swift Package Manager
**Use as CLI**
```shell
git clone https://github.com/yonaskolb/Stringly.git
cd Stringly
swift run stringly
```**Use as dependency**
Add the following to your Package.swift file's dependencies:
```swift
.package(url: "https://github.com/yonaskolb/Stringly.git", from: "0.7.0"),
```And then import wherever needed: `import StringlyKit`
## Example
Given a source `Strings.yml`:
```yml
auth: # grouping of strings
loginButton: Log In # If you don't specify a language it defaults to a base language
emailTitle:
en: Email # specifying a language
passwordTitle:
en: Password
de: Passwort # multiple languages
error: # infinitely nested groups
wrongEmailPassword: Incorrect email/password combination
home:
title: Hello {name} # this is a placeholder. Without a type defaults to %@ on apple platforms
postCount: "Total posts: {postCount:d}" # the placeholder now has a type %d
day: "Day: {}" # an unnamed placeholder
escaped: Text with escaped \{braces} # escape braces in text by using \{
articles: # this is a pluralized string
en: You have {articleCount:d} # placeholder will be replaced with pluralization
en.articleCount: # supports pluralizing multiple placeholders in a single string
none: no articles
one: one article
other: {articleCount:d} articles
```This generates `.swift`, `.strings`, and `.stringsdict` files for multiple languages.
The Swift file then allows usage like this:
```swift
errorLabel.text = Strings.auth.error.wrongEmailPassword
welcomeLabel.text = Strings.home.title(name: "John")
postsLabel.text = Strings.home.postCount(postCount: 10)
day.text = Strings.home.day("Monday")
articleLabel.text = Strings.home.articles(articleCount: 4)
```## Future Directions
- Comments and other data for keys
- Generate files for other platforms like Android `R.string` file or translation specific files
- Importing of translation files