-
Notifications
You must be signed in to change notification settings - Fork 0
Help! This doesn't translate!
The translation system in Khrysalis is extremely flexible and built for adding new translations dynamically.
Let's say we need support for URL encoding - specifically, calling the function URLEncoder.encode("string")
in Kotlin.
Add a file in your-project/src/main/equivalents
called your-name-here.swift.yaml
.
- id: java.net.URLEncoder.encode
type: call
template: "~0~.addingPercentEncoding(withAllowedCharacters: .alphanumerics)"
And likewise for TypeScript, add a file in your-project/src/main/equivalents
called your-name-here.ts.yaml
.
- id: java.net.URLEncoder.encode
type: call
template: encodeURIComponent(~0~)
What about if we need something from outside the standard libraries? Let's pull an example from the built-in equivalents, specifically a RatingBar
's number of stars on iOS:
# Swift
- id: android.widget.RatingBar.numStars
type: get
template:
pattern: ~this~.settings.totalStars
imports: [Cosmos] # import Cosmos
Or how about generating a random UUID in TypeScript?
# Typescript
- id: java.util.UUID.randomUUID
type: call
template:
pattern: v4()
imports:
v4: uuid # import { v4 } from 'uuid'
-
call
- A call to a function. -
get
- The reading of a variable. -
set
- The writing of a variable. -
type
- A type (e.g.Int
becomesnumber
in TypeScript -
typeRef
- A reference to the class of a type (e.g.Int::class
becomesNumber
in TypeScript)
The vast majority of the built-in equivalents are done in this same YAML
format. You can find those here:
More information can be found in the equivalents documentation.