Skip to content

Commit 7a0a686

Browse files
feat: migrate UI strings to resources
1 parent de351e2 commit 7a0a686

7 files changed

Lines changed: 506 additions & 117 deletions

File tree

composeApp/src/androidMain/kotlin/com/funny/data_saver/ui/ExampleComposables.android.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,33 @@ import com.funny.data_saver.core.DataSaverInterface
1111
import com.funny.data_saver.core.rememberDataSaverState
1212
import com.funny.data_saver_mmkv.DataSaverMMKV
1313
import com.tencent.mmkv.MMKV
14+
import composedatasaver.composeapp.generated.resources.Res
15+
import composedatasaver.composeapp.generated.resources.action_add_age
16+
import composedatasaver.composeapp.generated.resources.parcelable_name
17+
import composedatasaver.composeapp.generated.resources.saving_parcelable_android_description
18+
import composedatasaver.composeapp.generated.resources.saving_parcelable_title
19+
import org.jetbrains.compose.resources.stringResource
1420
import java.time.LocalTime
1521
import java.time.format.DateTimeFormatter
1622

1723
@Composable
1824
actual fun ParcelableExample() {
1925
ExampleCard(
20-
title = "Saving Parcelable",
21-
description = "基础实现里只有 MMKV 默认支持 Parcelable。"
26+
title = stringResource(Res.string.saving_parcelable_title),
27+
description = stringResource(Res.string.saving_parcelable_android_description)
2228
) {
2329
var parcelableExample by rememberDataSaverState(
2430
key = "parcelable_example",
25-
initialValue = ExampleParcelable("FunnySaltyFish", 20)
31+
initialValue = ExampleParcelable(
32+
stringResource(Res.string.parcelable_name),
33+
20
34+
)
2635
)
2736
Text(parcelableExample.toString())
2837
Button(onClick = {
2938
parcelableExample = parcelableExample.copy(age = parcelableExample.age + 1)
3039
}) {
31-
Text(text = "Add age by 1")
40+
Text(text = stringResource(Res.string.action_add_age))
3241
}
3342
}
3443
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<resources>
2+
<string name="example_bean_default_label">FunnySaltyFish</string>
3+
<string name="example_string_initial_value">FunnySaltyFish,点击输入</string>
4+
<string name="section_basic_states_title">基础状态</string>
5+
<string name="section_basic_states_description">展示 String、Boolean、Bean 和 Parcelable 等常见保存方式。</string>
6+
<string name="saving_string_title">保存 String</string>
7+
<string name="saving_string_description">输入后会立即保存。</string>
8+
<string name="string_value_label">String 值</string>
9+
<string name="saving_boolean_title">保存 Boolean</string>
10+
<string name="saving_boolean_description">切换状态后会自动持久化。</string>
11+
<string name="current_boolean_value">当前值:%1$s</string>
12+
<string name="saving_custom_bean_title">保存自定义 Bean</string>
13+
<string name="saving_custom_bean_description">通过类型转换器保存自定义对象。</string>
14+
<string name="add_bean_id">给 Bean id 加 1</string>
15+
<string name="section_collections_title">集合与类型</string>
16+
<string name="section_collections_description">集中查看列表、可空值、自定义转换器和密封类的保存效果。</string>
17+
<string name="section_behavior_title">行为示例</string>
18+
<string name="section_behavior_description">包含外部数据变化感知和页面销毁时保存等行为。</string>
19+
<string name="section_scope_title">作用域与异步</string>
20+
<string name="section_scope_description">包含 ViewModel、自定义协程域和耗时任务示例。</string>
21+
<string name="list_example_item_name">名称 %1$s</string>
22+
<string name="list_example_title">列表示例</string>
23+
<string name="list_example_description">列表内容的增删会被完整持久化。</string>
24+
<string name="action_add">添加</string>
25+
<string name="action_remove">移除</string>
26+
<string name="save_when_disposed_dialog_title">销毁时保存</string>
27+
<string name="save_when_disposed_initial_value">这个值只会在组件销毁时保存</string>
28+
<string name="dialog_value_label">对话框值</string>
29+
<string name="action_close">关闭</string>
30+
<string name="save_when_disposed_description">只有在对话框关闭时才触发保存,适合批量编辑后一次落盘。</string>
31+
<string name="action_open_dialog">打开对话框</string>
32+
<string name="nullable_bean_title">可空 Bean</string>
33+
<string name="nullable_bean_description">可空对象同样可以保存和恢复。</string>
34+
<string name="nullable_bean_not_null_label">我不是 null</string>
35+
<string name="action_set_not_null">设为非空</string>
36+
<string name="action_set_null">设为 null</string>
37+
<string name="sense_external_data_change_title">感知外部数据变化</string>
38+
<string name="sense_external_data_change_description">直接修改底层存储,界面会感知到变化并同步更新。</string>
39+
<string name="sense_external_data_change_value_1">Hello World(1)</string>
40+
<string name="sense_external_data_change_value_2">Hello World(2)</string>
41+
<string name="sense_external_data_change_var1">变量 1:%1$s</string>
42+
<string name="sense_external_data_change_var2">变量 2:%1$s</string>
43+
<string name="sense_external_data_change_new_value">Hello World %1$s</string>
44+
<string name="action_change_local_data">修改本地数据</string>
45+
<string name="action_not_null">设为非空</string>
46+
<string name="action_add_id">给 Id 加 1</string>
47+
<string name="sense_external_data_change_bean_label">非空</string>
48+
<string name="sense_external_data_change_list_initial_label">初始项</string>
49+
<string name="sense_external_data_change_list_added_label">新增项</string>
50+
<string name="custom_type_converter_title">自定义类型转换器</string>
51+
<string name="custom_type_converter_description">为默认不支持的类型自定义序列化逻辑。</string>
52+
<string name="action_randomly_change">随机修改</string>
53+
<string name="saving_sealed_class_title">保存密封类</string>
54+
<string name="saving_sealed_class_description">密封类也可以通过转换器稳定地保存。</string>
55+
<string name="theme_label">主题</string>
56+
<string name="theme_default">默认</string>
57+
<string name="theme_dynamic">动态</string>
58+
<string name="custom_scope_view_model_title">自定义 CoroutineScope 与 ViewModel</string>
59+
<string name="custom_scope_view_model_description">状态创建在 ViewModel 内,协程也绑定到 ViewModel 生命周期。</string>
60+
<string name="username_label">用户名</string>
61+
<string name="password_label">密码</string>
62+
<string name="time_consuming_log_start">开始保存数据,预计耗时 5 秒...</string>
63+
<string name="time_consuming_log_finish">保存完成。key=%1$s, data=%2$s</string>
64+
<string name="time_consuming_save_title">耗时保存</string>
65+
<string name="time_consuming_save_description">模拟慢速存储,在保存完成前会拦截返回动作。</string>
66+
<string name="action_submit_with_value">提交(当前值:%1$s)</string>
67+
<string name="time_consuming_wait_message">当前任务尚未完成,请等待保存结束。</string>
68+
<string name="hero_title">ComposeDataSaver 示例</string>
69+
<string name="hero_description">集中展示 ComposeDataSaver 的常见保存场景,可直接交互查看效果。</string>
70+
<string name="hero_log_drawer_title">日志抽屉</string>
71+
<string name="hero_log_drawer_description">点这里打开,或从页面左侧向右滑动查看日志。</string>
72+
<string name="action_open">打开</string>
73+
<string name="hero_preview_mode_notice">当前为预览模式,使用内存存储。</string>
74+
<string name="log_drawer_title">运行日志</string>
75+
<string name="log_drawer_description">查看读写日志和示例中的主动日志。</string>
76+
<string name="action_clear">清空</string>
77+
<string name="action_test_debug">测试 Debug</string>
78+
<string name="action_test_info">测试 Info</string>
79+
<string name="test_debug_log_message">测试 Debug 日志</string>
80+
<string name="test_info_log_message">测试 Info 日志</string>
81+
<string name="log_console_empty_text">暂时没有日志,操作主页面示例后可在这里查看。</string>
82+
<string name="log_level_label">日志级别:%1$s</string>
83+
<string name="log_console_empty_text_default">暂无日志。操作左侧示例后可在这里查看。</string>
84+
<string name="log_level_off">关闭</string>
85+
<string name="log_level_error">Error</string>
86+
<string name="log_level_warn">Warn</string>
87+
<string name="log_level_info">Info</string>
88+
<string name="log_level_debug">Debug</string>
89+
<string name="log_level_verbose">Verbose</string>
90+
<string name="saving_parcelable_title">保存 Parcelable</string>
91+
<string name="saving_parcelable_android_description">基础实现里只有 MMKV 默认支持 Parcelable。</string>
92+
<string name="parcelable_name">FunnySaltyFish</string>
93+
<string name="action_add_age">年龄加 1</string>
94+
<string name="saving_parcelable_unsupported_description">当前平台不提供 Parcelable 持久化示例。</string>
95+
<string name="saving_parcelable_unsupported_message">如需体验 Parcelable 持久化,请在 Android 端运行。</string>
96+
</resources>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<resources>
2+
<string name="example_bean_default_label">FunnySaltyFish</string>
3+
<string name="example_string_initial_value">FunnySaltyFish, tap to input</string>
4+
<string name="section_basic_states_title">Basic States</string>
5+
<string name="section_basic_states_description">Examples for saving String, Boolean, Bean, and Parcelable values.</string>
6+
<string name="saving_string_title">Saving String</string>
7+
<string name="saving_string_description">Changes are saved immediately after input.</string>
8+
<string name="string_value_label">String Value</string>
9+
<string name="saving_boolean_title">Saving Boolean</string>
10+
<string name="saving_boolean_description">The state is persisted automatically after toggling.</string>
11+
<string name="current_boolean_value">Current value: %1$s</string>
12+
<string name="saving_custom_bean_title">Saving Custom Bean</string>
13+
<string name="saving_custom_bean_description">Persist a custom object with a type converter.</string>
14+
<string name="add_bean_id">Add bean id</string>
15+
<string name="section_collections_title">Collections And Types</string>
16+
<string name="section_collections_description">Review how lists, nullable values, custom converters, and sealed classes are persisted.</string>
17+
<string name="section_behavior_title">Behavior Samples</string>
18+
<string name="section_behavior_description">Includes external data change sensing and save-on-dispose behavior.</string>
19+
<string name="section_scope_title">Scope And Async</string>
20+
<string name="section_scope_description">Includes ViewModel, custom coroutine scope, and long-running task examples.</string>
21+
<string name="list_example_item_name">Name %1$s</string>
22+
<string name="list_example_title">List Example</string>
23+
<string name="list_example_description">Additions and removals in the list are fully persisted.</string>
24+
<string name="action_add">Add</string>
25+
<string name="action_remove">Remove</string>
26+
<string name="save_when_disposed_dialog_title">Save When Disposed</string>
27+
<string name="save_when_disposed_initial_value">This one will be saved only when disposed</string>
28+
<string name="dialog_value_label">Dialog Value</string>
29+
<string name="action_close">Close</string>
30+
<string name="save_when_disposed_description">Saving is triggered only when the dialog closes, which is useful for batch edits.</string>
31+
<string name="action_open_dialog">Open Dialog</string>
32+
<string name="nullable_bean_title">Nullable Bean</string>
33+
<string name="nullable_bean_description">Nullable objects can also be saved and restored.</string>
34+
<string name="nullable_bean_not_null_label">I&apos;m not null</string>
35+
<string name="action_set_not_null">Set Not Null</string>
36+
<string name="action_set_null">Set Null</string>
37+
<string name="sense_external_data_change_title">Sense External Data Change</string>
38+
<string name="sense_external_data_change_description">Update the underlying storage directly and the UI will react to the change.</string>
39+
<string name="sense_external_data_change_value_1">Hello World(1)</string>
40+
<string name="sense_external_data_change_value_2">Hello World(2)</string>
41+
<string name="sense_external_data_change_var1">var1: %1$s</string>
42+
<string name="sense_external_data_change_var2">var2: %1$s</string>
43+
<string name="sense_external_data_change_new_value">Hello World %1$s</string>
44+
<string name="action_change_local_data">Change Local Data</string>
45+
<string name="action_not_null">Not Null</string>
46+
<string name="action_add_id">Add Id</string>
47+
<string name="sense_external_data_change_bean_label">not null</string>
48+
<string name="sense_external_data_change_list_initial_label">initial</string>
49+
<string name="sense_external_data_change_list_added_label">add</string>
50+
<string name="custom_type_converter_title">Custom Type Converter</string>
51+
<string name="custom_type_converter_description">Define custom serialization logic for unsupported types.</string>
52+
<string name="action_randomly_change">Randomly Change</string>
53+
<string name="saving_sealed_class_title">Saving Sealed Class</string>
54+
<string name="saving_sealed_class_description">Sealed classes can also be persisted reliably through a converter.</string>
55+
<string name="theme_label">Theme</string>
56+
<string name="theme_default">Default</string>
57+
<string name="theme_dynamic">Dynamic</string>
58+
<string name="custom_scope_view_model_title">Custom CoroutineScope And ViewModel</string>
59+
<string name="custom_scope_view_model_description">State is created inside the ViewModel, and coroutines follow the ViewModel lifecycle.</string>
60+
<string name="username_label">Username</string>
61+
<string name="password_label">Password</string>
62+
<string name="time_consuming_log_start">Start saving data. This will take 5 seconds...</string>
63+
<string name="time_consuming_log_finish">Finish saving data. key=%1$s, data=%2$s</string>
64+
<string name="time_consuming_save_title">Time Consuming Save</string>
65+
<string name="time_consuming_save_description">Simulates slow storage and blocks the back action until saving finishes.</string>
66+
<string name="action_submit_with_value">Submit (current value: %1$s)</string>
67+
<string name="time_consuming_wait_message">The current job is not finished. Please wait until it completes.</string>
68+
<string name="hero_title">ComposeDataSaver Examples</string>
69+
<string name="hero_description">A compact showcase of common ComposeDataSaver persistence scenarios with live interaction.</string>
70+
<string name="hero_log_drawer_title">Log Drawer</string>
71+
<string name="hero_log_drawer_description">Open it here, or swipe right from the left edge to inspect logs.</string>
72+
<string name="action_open">Open</string>
73+
<string name="hero_preview_mode_notice">Preview mode is active. Using in-memory storage.</string>
74+
<string name="log_drawer_title">Runtime Logs</string>
75+
<string name="log_drawer_description">Inspect read/write logs and the manual logs emitted by these examples.</string>
76+
<string name="action_clear">Clear</string>
77+
<string name="action_test_debug">Test Debug</string>
78+
<string name="action_test_info">Test Info</string>
79+
<string name="test_debug_log_message">Test Debug log</string>
80+
<string name="test_info_log_message">Test Info log</string>
81+
<string name="log_console_empty_text">No logs yet. Interact with the examples on the main page to inspect them here.</string>
82+
<string name="log_level_label">Log Level: %1$s</string>
83+
<string name="log_console_empty_text_default">No logs yet. Use the examples on the left to inspect output here.</string>
84+
<string name="log_level_off">Off</string>
85+
<string name="log_level_error">Error</string>
86+
<string name="log_level_warn">Warn</string>
87+
<string name="log_level_info">Info</string>
88+
<string name="log_level_debug">Debug</string>
89+
<string name="log_level_verbose">Verbose</string>
90+
<string name="saving_parcelable_title">Saving Parcelable</string>
91+
<string name="saving_parcelable_android_description">Only MMKV supports Parcelable in the base implementation.</string>
92+
<string name="parcelable_name">FunnySaltyFish</string>
93+
<string name="action_add_age">Add age by 1</string>
94+
<string name="saving_parcelable_unsupported_description">This platform does not provide a Parcelable persistence sample.</string>
95+
<string name="saving_parcelable_unsupported_message">Run the Android target if you want to try Parcelable persistence.</string>
96+
</resources>

0 commit comments

Comments
 (0)