Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex009 committed Sep 10, 2019
2 parents 69a1114 + 1144196 commit 1fbd33c
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 10 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object Versions {

const val kotlin = "1.3.50"

private const val mokoResources = "0.2.0"
private const val mokoResources = "0.3.0"

object Plugins {
const val android = "3.4.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ actual sealed class StringDesc {
}
}

actual data class Composition actual constructor(val args: List<StringDesc>) : StringDesc() {
actual data class Composition actual constructor(val args: List<StringDesc>, val separator: String?) : StringDesc() {
override fun toString(context: Context): String {
return StringBuilder().apply {
args.forEach {
append(it.toString(context))
args.forEachIndexed { index, stringDesc ->
if(index != 0 && separator != null) {
append(separator)
}
append(stringDesc.toString(context))
}
}.toString()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ expect sealed class StringDesc {
}

class Raw(string: String) : StringDesc
class Composition(args: List<StringDesc>) : StringDesc
class Composition(args: List<StringDesc>, separator: String? = null) : StringDesc
}

fun String.desc() = StringDesc.Raw(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ actual sealed class StringDesc {
}
}

actual data class Composition actual constructor(val args: List<StringDesc>) : StringDesc() {
actual data class Composition actual constructor(val args: List<StringDesc>, val separator: String?) : StringDesc() {
override fun toLocalizedString(formatter: Formatter): String {
return StringBuilder().apply {
args.forEach {
append(it.toLocalizedString(formatter))
args.forEachIndexed { index, stringDesc ->
if(index != 0 && separator != null) {
append(separator)
}
append(stringDesc.toLocalizedString(formatter))
}
}.toString()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class MainActivity : AppCompatActivity() {

val imageView: ImageView = findViewById(R.id.imageView)
val textView: TextView = findViewById(R.id.textView)
val stringDescTextView: TextView = findViewById(R.id.stringDescTextView)

val strings = Testing.getStrings()
val text = strings.joinToString("\n") { it.toString(context = this) }
Expand All @@ -23,5 +24,7 @@ class MainActivity : AppCompatActivity() {

imageView.setImageResource(drawable.drawableResId)
textView.text = text

stringDescTextView.text = Testing.getStringDesc().toString(context = this)
}
}
5 changes: 5 additions & 0 deletions sample/android-app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/stringDescTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
16 changes: 14 additions & 2 deletions sample/ios-app/src/Resources/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@
</constraints>
</imageView>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="ucI-dH-xD1">
<rect key="frame" x="16" y="180" width="288" height="388"/>
<rect key="frame" x="16" y="180" width="288" height="190"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<string key="text">Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.</string>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="NHE-5E-PG4">
<rect key="frame" x="16" y="378" width="288" height="190"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<string key="text">Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.</string>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
Expand All @@ -55,16 +62,21 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="ucI-dH-xD1" firstAttribute="leading" secondItem="KxK-oh-5KO" secondAttribute="leadingMargin" id="6So-2f-f1p"/>
<constraint firstAttribute="trailingMargin" secondItem="NHE-5E-PG4" secondAttribute="trailing" id="Jzj-HF-PZf"/>
<constraint firstItem="Ube-gc-16Y" firstAttribute="centerX" secondItem="KxK-oh-5KO" secondAttribute="centerX" id="OiW-o5-Vxr"/>
<constraint firstAttribute="trailingMargin" secondItem="ucI-dH-xD1" secondAttribute="trailing" id="am7-fq-7Rn"/>
<constraint firstItem="ucI-dH-xD1" firstAttribute="top" secondItem="Ube-gc-16Y" secondAttribute="bottom" constant="8" id="c0l-6H-3Zi"/>
<constraint firstItem="NHE-5E-PG4" firstAttribute="top" secondItem="ucI-dH-xD1" secondAttribute="bottom" constant="8" id="h5v-fF-GIo"/>
<constraint firstItem="NHE-5E-PG4" firstAttribute="leading" secondItem="KxK-oh-5KO" secondAttribute="leadingMargin" id="jKM-u3-qb6"/>
<constraint firstItem="Ube-gc-16Y" firstAttribute="top" secondItem="gcA-zH-akF" secondAttribute="bottom" constant="8" id="ohz-xd-Wfq"/>
<constraint firstItem="gTY-6T-yQv" firstAttribute="top" secondItem="ucI-dH-xD1" secondAttribute="bottom" id="uUL-qs-aQv"/>
<constraint firstItem="gTY-6T-yQv" firstAttribute="top" secondItem="NHE-5E-PG4" secondAttribute="bottom" id="sUQ-aM-bLf"/>
<constraint firstItem="NHE-5E-PG4" firstAttribute="height" secondItem="ucI-dH-xD1" secondAttribute="height" id="sjf-GQ-bOC"/>
</constraints>
</view>
<navigationItem key="navigationItem" title="Test" id="0jM-60-fjM"/>
<connections>
<outlet property="imageView" destination="Ube-gc-16Y" id="iCx-HQ-gln"/>
<outlet property="stringDescTextView" destination="NHE-5E-PG4" id="dAt-lx-6ib"/>
<outlet property="textView" destination="ucI-dH-xD1" id="VYE-zp-vuP"/>
</connections>
</viewController>
Expand Down
3 changes: 3 additions & 0 deletions sample/ios-app/src/TestViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class TestViewController: UIViewController {

@IBOutlet private var imageView: UIImageView!
@IBOutlet private var textView: UITextView!
@IBOutlet private var stringDescTextView: UITextView!

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -21,5 +22,7 @@ class TestViewController: UIViewController {

imageView.image = UIImage(named: drawable.assetImageName)
textView.text = strings.map { $0.localized() }.joined(separator: "\n")

stringDescTextView.text = testing.getStringDesc().localized()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package com.icerockdev.library
import dev.icerock.moko.resources.DrawableResource
import dev.icerock.moko.resources.desc.StringDesc
import dev.icerock.moko.resources.desc.desc
import dev.icerock.moko.resources.desc.plus

object Testing {
fun getStrings(): List<StringDesc> {
Expand All @@ -26,4 +27,42 @@ object Testing {
fun getDrawable(): DrawableResource {
return MR.drawables.test_drawable
}

fun getStringDesc(): StringDesc {
// create simple string
val simpleString = StringDesc.Resource(MR.strings.test)
val simpleStringExt = MR.strings.test.desc()

// create formatted string
val formattedString = StringDesc.ResourceFormatted(MR.strings.format, 9)

// create plural
val simplePlural = StringDesc.Plural(MR.plurals.test_plural, 10)
val simplePluralExt = MR.plurals.test_plural.desc(10)

// create formatted plural
val formattedPlural = StringDesc.PluralFormatted(MR.plurals.my_plural, 10, 10)

// raw string
val simpleRaw = StringDesc.Raw("raw string")
val simpleRawExt = "raw string".desc()

// composition
val composition = simpleString + simpleRaw

// result as list composition
val list = listOf(
simpleString,
simpleStringExt,
formattedString,
simplePlural,
simplePluralExt,
formattedPlural,
simpleRaw,
simpleRawExt,
composition
)

return StringDesc.Composition(list, separator = "\n")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@
<item quantity="many">many</item>
<item quantity="other">other</item>
</plural>
<plural name="my_plural">
<item quantity="zero">no items</item>
<item quantity="one">%d item</item>
<item quantity="two">%d items</item>
<item quantity="few">%d items</item>
<item quantity="many">%d items</item>
<item quantity="other">%d items</item>
</plural>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<string name="test2">test 2</string>
<string name="test3">test 3</string>
<string name="common.name">Test Project</string>
<string name="format">Test data %d</string>
</resources>
8 changes: 8 additions & 0 deletions sample/mpp-library/src/commonMain/resources/MR/ru/plurals.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@
<item quantity="many">много</item>
<item quantity="other">другое</item>
</plural>
<plural name="my_plural">
<item quantity="zero">нет элементов</item>
<item quantity="one">%d элемент</item>
<item quantity="two">%d элемента</item>
<item quantity="few">%d элементов</item>
<item quantity="many">%d элементов</item>
<item quantity="other">%d элемента</item>
</plural>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<string name="test2">тест 2</string>
<string name="test3">тест 3</string>
<string name="common.name">Тестовый проект</string>
<string name="format">Тестовые данные %d</string>
</resources>

0 comments on commit 1fbd33c

Please sign in to comment.