Coder Social home page Coder Social logo

stringly's Introduction

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 install yonaskolb/stringly

Swift Package Manager

Use as CLI

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:

.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:

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:

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

stringly's People

Contributors

yonaskolb avatar janiduw avatar

Stargazers

Andrin Meier avatar Scripts and Things avatar Brad Pillow avatar David Smith avatar Igor Zubkov avatar Roman Podymov avatar fernando.ios(페르난도) avatar Takuma Osada avatar ryohey avatar Bohdan avatar Narcis avatar Vinh Nguyen avatar Omar avatar Marcus Kida avatar Eneko Alonso avatar Daniel Kalintsev avatar Scott Talbot avatar horita-yuya avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

janiduw

stringly's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.