Skip to content

Commit d6683d7

Browse files
authored
Merge branch 'trunk' into feature/custom-branch-webview
2 parents cc44cf0 + 6e93b5d commit d6683d7

28 files changed

+795
-343
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
### Next Release
22
- Feature: Allow to specify custom branch for WebView-native apps
3+
- Feature: Load and apply store specific i18n texts runtime
4+
- Feature: Build and validate fonts taking into account store specific i18n texts
35

46
### 2.10.0
57
- Refactor: Optimize product load time by using async coroutines

scripts/build_fonts.sh

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ LOCALIZATION_DIRS=(
1010
./virtusize-core/src/main/res
1111
)
1212
BYPASS_CACHE=$RANDOM
13+
SUPPORTED_STORE_NAMES=("united_arrows")
1314

1415
# Rename the font file name and it's metadata to ensure they match.
1516
# The inner font name change is important, so it can be loaded as:
@@ -40,6 +41,32 @@ rename_font() {
4041
echo "Font renamed: $new_name"
4142
}
4243

44+
# Merge local strings with remote json-strings and use this merged file for validation
45+
prepare_strings() {
46+
local language=$1
47+
local text_file=$2
48+
49+
# Combine multiple localization files into a single
50+
{
51+
> $text_file # Clear the output file if it exists
52+
53+
# Loop through each directory in the array
54+
for dir in "${LOCALIZATION_DIRS[@]}"; do
55+
file=$dir/values-$language/strings.xml
56+
cat $file >> $text_file
57+
echo "\n" >> "$text_file" # Add a newline for separation
58+
done
59+
}
60+
61+
# shared remote i18n texts
62+
curl "https://i18n.virtusize.com/stg/bundle-payloads/aoyama/${language}?random=$BYPASS_CACHE" >> $text_file
63+
64+
# remote store specific texts
65+
for store_name in "${SUPPORTED_STORE_NAMES[@]}"; do
66+
curl "https://integration.virtusize.jp/staging/$store_name/customText.json" >> $text_file
67+
done
68+
}
69+
4370
# Combine multiple localization files into one file.
4471
# The file is stored into a single
4572
# Return file path
@@ -51,18 +78,7 @@ combine_localization_files() {
5178
mkdir -p $tmp_dir
5279
local output_file=$tmp_dir/combined_strings_$language.xml
5380

54-
# Clear the output file if it exists
55-
> $output_file
56-
57-
# Loop through each directory in the array
58-
for dir in "${LOCALIZATION_DIRS[@]}"; do
59-
file=$dir/values-$language/strings.xml
60-
cat $file >> $output_file
61-
echo "\n" >> "$output_file" # Add a newline for separation
62-
done
63-
64-
# Merge remote i18n strings into the local localization file
65-
curl "https://i18n.virtusize.com/stg/bundle-payloads/aoyama/${language}?random=$BYPASS_CACHE" >> $output_file
81+
prepare_strings $language $output_file
6682

6783
echo $output_file
6884
}

scripts/validate_fonts.sh

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ LOCALIZATION_DIRS=(
77
)
88
SKIP_CHARS=("0000c6d0") # skip '%' symbol, as it breaks the parsing
99
BYPASS_CACHE=$RANDOM
10+
SUPPORTED_STORE_NAMES=("united_arrows")
1011

1112
# Strategy:
1213
# 1. Fetch all the glyphs from the font file
@@ -71,10 +72,36 @@ validate_font_symbols() {
7172
else
7273
echo "ERROR: Localization file '$text_file' is NOT fully supported by the font '$(basename "$font_file")'. See missing characters above."
7374
exit 1
74-
fi
75+
fi
7576
}
7677
}
7778

79+
# Merge local strings with remote json-strings and use this merged file for validation
80+
prepare_strings() {
81+
local language=$1
82+
local text_file=$2
83+
84+
# Combine multiple localization files into a single
85+
{
86+
> $text_file # Clear the output file if it exists
87+
88+
# Loop through each directory in the array
89+
for dir in "${LOCALIZATION_DIRS[@]}"; do
90+
file=$dir/values-$language/strings.xml
91+
cat $file >> $text_file
92+
echo "\n" >> "$text_file" # Add a newline for separation
93+
done
94+
}
95+
96+
# shared remote i18n texts
97+
curl "https://i18n.virtusize.com/stg/bundle-payloads/aoyama/${language}?random=$BYPASS_CACHE" >> $text_file
98+
99+
# remote store specific texts
100+
for store_name in "${SUPPORTED_STORE_NAMES[@]}"; do
101+
curl "https://integration.virtusize.jp/staging/$store_name/customText.json" >> $text_file
102+
done
103+
}
104+
78105
# Wrapper function
79106
validate_font() {
80107
local font=$1
@@ -85,20 +112,8 @@ validate_font() {
85112
# Prepare temp directory
86113
mkdir -p $tmp_dir
87114

88-
# Combine multiple localization files into a single
89-
{
90-
> $combined_text_file # Clear the output file if it exists
91-
92-
# Loop through each directory in the array
93-
for dir in "${LOCALIZATION_DIRS[@]}"; do
94-
file=$dir/values-$language/strings.xml
95-
cat $file >> $combined_text_file
96-
echo "\n" >> "$combined_text_file" # Add a newline for separation
97-
done
98-
}
99-
100115
# Merge remote i18n strings into the local localization file
101-
curl "https://i18n.virtusize.com/stg/bundle-payloads/aoyama/${language}?random=$BYPASS_CACHE" >> $combined_text_file
116+
prepare_strings $language $combined_text_file
102117

103118
# Validate font
104119
validate_font_symbols $FONTS_DIR/$font $combined_text_file $tmp_dir

virtusize-core/src/main/java/com/virtusize/android/data/local/VirtusizeEnvironment.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ fun VirtusizeEnvironment.servicesApiUrl(): String {
5353
}
5454
}
5555

56+
/**
57+
* Gets the integration API URL corresponding to the Virtusize Environment
58+
* @return A String value of the services API URL
59+
*/
60+
fun VirtusizeEnvironment.integrationApiUrl(): String {
61+
return when (this) {
62+
VirtusizeEnvironment.TESTING -> "https://integration.virtusize.jp/staging"
63+
VirtusizeEnvironment.STAGING -> "https://integration.virtusize.com/staging"
64+
VirtusizeEnvironment.GLOBAL -> "https://integration.virtusize.com/production"
65+
VirtusizeEnvironment.JAPAN -> "https://integration.virtusize.jp/production"
66+
VirtusizeEnvironment.KOREA -> "https://integration.virtusize.kr/production"
67+
}
68+
}
69+
5670
fun VirtusizeEnvironment.sizeRecommendationApiBaseUrl(): String {
5771
return when (this) {
5872
VirtusizeEnvironment.TESTING -> "https://size-recommendation.staging.virtusize.jp"

virtusize-core/src/main/java/com/virtusize/android/data/remote/I18nLocalization.kt

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package com.virtusize.android.data.remote
22

3-
import android.content.Context
43
import com.virtusize.android.data.local.SizeComparisonRecommendedSize
54
import com.virtusize.android.data.local.VirtusizeLanguage
6-
import com.virtusize.android.data.local.isUnitedArrows
7-
import com.virtusize.android.network.VirtusizeApi
8-
import com.virtusize.android.util.ConfigurationUtils
95
import com.virtusize.android.util.I18nConstants
106

117
/**
@@ -68,19 +64,8 @@ data class I18nLocalization(
6864
/**
6965
* Gets the recommendation text for a multi-size product based on a user body profile
7066
*/
71-
internal fun getMultiSizeBodyProfileText(
72-
context: Context,
73-
bodyProfileRecommendedSizeName: String,
74-
): String {
75-
val configuredContext = ConfigurationUtils.getConfiguredContext(context, language)
76-
// Override the willFitResultText for United Arrows
77-
val adjustedWillFitResultText =
78-
if (VirtusizeApi.currentStoreId.isUnitedArrows) {
79-
configuredContext.getString(com.virtusize.android.core.R.string.inpage_will_fit_result_text_united_arrows)
80-
} else {
81-
willFitResultText
82-
}
83-
return "$adjustedWillFitResultText ${I18nConstants.BOLD_START_PLACEHOLDER}" +
67+
internal fun getMultiSizeBodyProfileText(bodyProfileRecommendedSizeName: String): String {
68+
return "$willFitResultText ${I18nConstants.BOLD_START_PLACEHOLDER}" +
8469
"$bodyProfileRecommendedSizeName${I18nConstants.BOLD_END_PLACEHOLDER}"
8570
}
8671
}

virtusize-core/src/main/java/com/virtusize/android/data/remote/Product.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ data class Product(
5252
)
5353
else ->
5454
multiSizeText(
55-
context = context,
5655
i18nLocalization,
5756
sizeComparisonRecommendedSize,
5857
bodyProfileRecommendedSizeName,
@@ -103,14 +102,12 @@ data class Product(
103102
* Gets the text for a multi-size product
104103
*/
105104
private fun multiSizeText(
106-
context: Context,
107105
i18nLocalization: I18nLocalization,
108106
sizeComparisonRecommendedSize: SizeComparisonRecommendedSize?,
109107
bodyProfileRecommendedSizeName: String?,
110108
): String {
111109
bodyProfileRecommendedSizeName?.let {
112110
return i18nLocalization.getMultiSizeBodyProfileText(
113-
context = context,
114111
bodyProfileRecommendedSizeName = bodyProfileRecommendedSizeName,
115112
)
116113
}

virtusize-core/src/main/java/com/virtusize/android/network/VirtusizeApi.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.virtusize.android.data.local.VirtusizeOrder
1111
import com.virtusize.android.data.local.VirtusizeProduct
1212
import com.virtusize.android.data.local.defaultApiUrl
1313
import com.virtusize.android.data.local.eventApiUrl
14+
import com.virtusize.android.data.local.integrationApiUrl
1415
import com.virtusize.android.data.local.servicesApiUrl
1516
import com.virtusize.android.data.local.sizeRecommendationApiBaseUrl
1617
import com.virtusize.android.data.local.virtusizeUrl
@@ -338,6 +339,22 @@ object VirtusizeApi {
338339
return ApiRequest(url, HttpMethod.GET)
339340
}
340341

342+
/**
343+
* Gets a API request for retrieving custom i18n texts for specific store
344+
* @see ApiRequest
345+
*/
346+
fun getStoreSpecificI18n(storeName: String): ApiRequest {
347+
val url =
348+
Uri.parse(
349+
environment.integrationApiUrl() +
350+
VirtusizeEndpoint.StoreI18N(storeName).path,
351+
)
352+
.buildUpon()
353+
.build()
354+
.toString()
355+
return ApiRequest(url, HttpMethod.GET)
356+
}
357+
341358
fun getSessions(): ApiRequest {
342359
val url =
343360
Uri.parse(environment.defaultApiUrl() + VirtusizeEndpoint.Sessions.path)

virtusize-core/src/main/java/com/virtusize/android/network/VirtusizeApiTask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ class VirtusizeApiTask(
326326

327327
else -> {
328328
val jsonObject = JSONObject(streamString)
329-
jsonParser?.parse(jsonObject)
329+
if (jsonParser == null) jsonObject else jsonParser?.parse(jsonObject)
330330
}
331331
}
332332

virtusize-core/src/main/java/com/virtusize/android/network/VirtusizeEndpoint.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,8 @@ sealed interface VirtusizeEndpoint {
7575
data object I18N : VirtusizeEndpoint {
7676
override val path: String = "/bundle-payloads/aoyama/"
7777
}
78+
79+
data class StoreI18N(val storeName: String) : VirtusizeEndpoint {
80+
override val path: String = "/$storeName/customText.json"
81+
}
7882
}

virtusize-core/src/main/java/com/virtusize/android/util/Extensions.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import androidx.appcompat.app.AppCompatActivity
1515
import androidx.core.content.ContextCompat
1616
import androidx.core.content.res.ResourcesCompat
1717
import com.virtusize.android.data.remote.I18nLocalization
18+
import org.json.JSONException
19+
import org.json.JSONObject
1820

1921
/**
2022
* The Context extension function to get the string by the string resource name
@@ -145,3 +147,27 @@ fun Context.getActivity(): AppCompatActivity? {
145147
}
146148
return null
147149
}
150+
151+
/**
152+
* Merge "source" into "current". If fields have equal name, merge them recursively.
153+
* @return the merged object.
154+
*/
155+
@Throws(JSONException::class)
156+
fun JSONObject.deepMerge(source: JSONObject): JSONObject {
157+
val target = this
158+
for (key in source.keys()) {
159+
val value = source[key]
160+
if (!target.has(key)) {
161+
// new value for "key":
162+
target.put(key, value)
163+
} else {
164+
// existing value for "key" - recursively deep merge:
165+
if (value is JSONObject) {
166+
target.getJSONObject(key).deepMerge(value)
167+
} else {
168+
target.put(key, value)
169+
}
170+
}
171+
}
172+
return target
173+
}

0 commit comments

Comments
 (0)