niknovak / nstack-custom

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NStack

Swift Version Vapor Version Circle CI codebeat badge codecov Readme Score GitHub license

This package is a wrapper around the NStack.io API.

Supports the following features:

  • Translate

πŸ“¦ Installation

Update your Package.swift file.

.Package(url: "https://github.com/nodes-vapor/nstack.git", majorVersion: 2)

Config

Create config nstack.json

{
    "log": false,
    "defaultApplication": "appOne",
    "translate": {
        "defaultPlatform": "backend",
        "defaultLanguage": "en-UK",
        "cacheInMinutes": 60
    },
    "applications": [
        {
            "name": "appOne",
            "applicationId": "secret",
            "restKey": "secret",
            "masterKey": "secret"
        }
    ]
}

Make sure that client is set to foundation in droplet.json because the engine client does not properly support the required SSL connections.

  ...
  "client": "foundation",
  ...

Getting started πŸš€

Config+Setup.swift

import NStack

And add provider

try addProvider(NStackProvider.self)

Droplet+Setup.swift

import NStack

And register the nstack leaf tag

extension Droplet {
    // ...
    guard let leaf = view as? LeafRenderer else {
        fatalError("Leaf not configured.")
    }

    leaf.stem.register(NStackTag(nStack: self.nstack))
    // ...
}

Usages

Consider making a easy accessible var

let translate = drop.nstack?.application.translate
// With default language and platform
translate?.get(section: "default", key: "ok")

// Specifying language and platform and replacing placeholders
translate?.get(platform: "backend", language: "en-UK", section: "default", key: "saveSuccess", replace: ["model": "test"])

Leaf usage yields a translated string or the given key if translation fails

// Get translation for camelCasedSection.camelCasedKey
#nstack("camelCasedSection", "camelCasedKey")

// Get translation for camelCasedSection.camelCasedKey and replace searchString1 with replaceString1 etc
#nstack("camelCasedSection", "camelCasedKey", "searchString1", "replaceString1", "searchString2", "replaceString2", ...)

πŸ† Credits

This package is developed and maintained by the Vapor team at Nodes. The package owner for this project is Rasmus.

πŸ“„ License

This package is open-sourced software licensed under the MIT license

About

License:MIT License


Languages

Language:Swift 100.0%