├── .editorconfig
├── .gitignore
├── AvaloniaExtensions.sln
├── Directory.Build.props
├── LICENSE
├── README.md
├── README.zh-CN.md
├── avalonia-using-xml-files-for-internationalization.md
├── doc
└── imgs
│ ├── ResourceConfig.png
│ └── ResourceDir.png
├── logo.ico
├── logo.png
└── src
├── Avalonia.XmlTranslator.Demo
├── App.axaml
├── App.axaml.cs
├── Avalonia.XmlTranslator.Demo.csproj
├── I18n
│ ├── Language.cs
│ ├── Language.tt
│ ├── en-US.xml
│ ├── ja-JP.xml
│ ├── zh-CN.xml
│ └── zh-Hant.xml
├── Program.cs
├── Roots.xml
├── ViewModels
│ ├── MainWindowViewModel.cs
│ └── ViewModelBase.cs
├── Views
│ ├── MainWindow.axaml
│ └── MainWindow.axaml.cs
└── app.manifest
├── AvaloniaExtensions.Axaml.Demo
├── App.axaml
├── App.axaml.cs
├── Assets
│ ├── cloud.png
│ ├── logo.ico
│ └── logo.png
├── AvaloniaExtensions.Axaml.Demo.csproj
├── I18n
│ ├── Language.cs
│ ├── Language.tt
│ ├── Resources.Designer.cs
│ ├── Resources.ja-JP.resx
│ ├── Resources.resx
│ ├── Resources.zh-CN.resx
│ └── Resources.zh-Hant.resx
├── Models
│ ├── AlarmStatus.cs
│ └── RunStatusKind.cs
├── Program.cs
├── Styles
│ └── Brushes.axaml
├── ViewLocator.cs
├── ViewModels
│ ├── MainWindowViewModel.cs
│ └── ViewModelBase.cs
├── Views
│ ├── MainWindow.axaml
│ └── MainWindow.axaml.cs
└── app.manifest
├── AvaloniaExtensions.Axaml
├── AssemblyInfo.cs
├── AvaloniaExtensions.Axaml.csproj
├── Converters
│ ├── EnumToBooleanConverter.cs
│ ├── I18n
│ │ ├── I18nConverter.cs
│ │ ├── I18nKeyConverter.cs
│ │ └── I18nValueConverter.cs
│ ├── If
│ │ ├── IfConditionConverter.cs
│ │ └── IfConverter.cs
│ └── IsCollectionEmptyConverter.cs
├── ExtensionMethods
│ └── ObjectExtensions.cs
└── Markup
│ ├── Constants.cs
│ ├── I18n
│ ├── ArgCollection.cs
│ ├── I18nBinding.cs
│ ├── I18nExtension.cs
│ └── I18nManager.cs
│ ├── If
│ ├── IfBinding.cs
│ └── IfExtension.cs
│ └── MultiBindingExtensionBase.cs
├── AvaloniaExtensions.Tests
├── AvaloniaExtensions.Tests.csproj
├── LanguageXmlReadTest.cs
├── MSTestSettings.cs
└── en-US.xml
└── AvaloniaXmlTranslator
├── AssemblyInfo.cs
├── AvaloniaXmlTranslator.csproj
├── Consts.cs
├── Converters
├── I18nConverter.cs
├── I18nKeyConverter.cs
└── I18nValueConverter.cs
├── I18nManager.cs
├── Markup
├── ArgCollection.cs
├── I18nBinding.cs
└── I18nExtension.cs
├── Models
└── LocalizationLanguage.cs
└── MultiBindingExtensionBase.cs
/.editorconfig:
--------------------------------------------------------------------------------
1 | # To learn more about .editorconfig see https://aka.ms/editorconfigdocs
2 |
3 | # top-most EditorConfig file
4 | root = true
5 |
6 | # Default settings:
7 | # A newline ending every file
8 | # Use 4 spaces as indentation
9 | [*]
10 | insert_final_newline = true
11 | indent_style = space
12 | indent_size = 4
13 | trim_trailing_whitespace = true
14 |
15 | [*.json]
16 | indent_size = 2
17 |
18 | [*.{cs,xaml}]
19 | charset = utf-8
20 | end_of_line = crlf
21 |
22 | # C# files
23 | [*.cs]
24 | # New line preferences
25 | csharp_new_line_before_open_brace = all
26 | csharp_new_line_before_else = true
27 | csharp_new_line_before_catch = true
28 | csharp_new_line_before_finally = true
29 | csharp_new_line_before_members_in_object_initializers = true
30 | csharp_new_line_before_members_in_anonymous_types = true
31 | csharp_new_line_between_query_expression_clauses = true
32 |
33 | # Indentation preferences
34 | csharp_indent_block_contents = true
35 | csharp_indent_braces = false
36 | csharp_indent_case_contents = true
37 | csharp_indent_case_contents_when_block = true
38 | csharp_indent_switch_labels = true
39 | csharp_indent_labels = one_less_than_current
40 |
41 | # Parentheses preferences
42 | dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary : silent
43 | dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary : silent
44 | dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary : silent
45 | dotnet_style_parentheses_in_other_operators = never_if_unnecessary : silent
46 |
47 | # Modifier preferences
48 | csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async : suggestion
49 | dotnet_style_require_accessibility_modifiers = for_non_interface_members : warning
50 |
51 | # avoid this. unless absolutely necessary
52 | dotnet_style_qualification_for_field = false : suggestion
53 | dotnet_style_qualification_for_property = false : suggestion
54 | dotnet_style_qualification_for_method = false : suggestion
55 | dotnet_style_qualification_for_event = false : suggestion
56 |
57 | # Types: use keywords instead of BCL types, and permit var only when the type is clear
58 | csharp_style_var_for_built_in_types = false : suggestion
59 | csharp_style_var_when_type_is_apparent = false : none
60 | csharp_style_var_elsewhere = false : suggestion
61 | dotnet_style_predefined_type_for_locals_parameters_members = true : suggestion
62 | dotnet_style_predefined_type_for_member_access = true : suggestion
63 |
64 | # Naming Conventions
65 |
66 | dotnet_naming_style.pascal_case_style.capitalization = pascal_case
67 |
68 | dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
69 | dotnet_naming_style.camel_case_underscore_style.required_prefix = _
70 |
71 | dotnet_naming_style.interfaces_style.capitalization = pascal_case
72 | dotnet_naming_style.interfaces_style.required_prefix = I
73 |
74 | # name all constant fields using PascalCase
75 | dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
76 | dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
77 | dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
78 | dotnet_naming_symbols.constant_fields.applicable_kinds = field
79 | dotnet_naming_symbols.constant_fields.required_modifiers = const
80 |
81 | # static fields using PascalCase
82 | dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion
83 | dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
84 | dotnet_naming_rule.static_fields_should_have_prefix.style = pascal_case_style
85 | dotnet_naming_symbols.static_fields.applicable_kinds = field
86 | dotnet_naming_symbols.static_fields.required_modifiers = static
87 | dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected
88 |
89 | # internal and private fields should be _camelCase
90 | dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
91 | dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
92 | dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
93 | dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
94 | dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
95 |
96 | # interfaces must have an I prefix
97 | dotnet_naming_rule.interfaces_must_be_interfaces_style.severity = suggestion
98 | dotnet_naming_rule.interfaces_must_be_interfaces_style.symbols = interfaces
99 | dotnet_naming_rule.interfaces_must_be_interfaces_style.style = interfaces_style
100 | dotnet_naming_symbols.interfaces.applicable_kinds = interface
101 | dotnet_naming_symbols.interfaces.applicable_accessibilities = *
102 |
103 | # Code style defaults
104 | csharp_using_directive_placement = outside_namespace : suggestion
105 | dotnet_sort_system_directives_first = true
106 | csharp_prefer_braces = true : suggestion
107 | csharp_preserve_single_line_blocks = true : none
108 | csharp_preserve_single_line_statements = false : none
109 | csharp_prefer_static_local_function = true : suggestion
110 | csharp_prefer_simple_using_statement = false : none
111 | csharp_style_prefer_switch_expression = true : suggestion
112 |
113 | # Code quality
114 | dotnet_style_readonly_field = true : suggestion
115 | dotnet_code_quality_unused_parameters = non_public : suggestion
116 |
117 | # Expression-level preferences
118 | dotnet_style_object_initializer = true : suggestion
119 | dotnet_style_collection_initializer = true : suggestion
120 | dotnet_style_explicit_tuple_names = true : suggestion
121 | dotnet_style_coalesce_expression = true : suggestion
122 | dotnet_style_null_propagation = true : suggestion
123 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true : suggestion
124 | dotnet_style_prefer_inferred_tuple_names = true : suggestion
125 | dotnet_style_prefer_inferred_anonymous_type_member_names = true : suggestion
126 | dotnet_style_prefer_auto_properties = true : suggestion
127 | dotnet_style_prefer_conditional_expression_over_assignment = true : refactoring
128 | dotnet_style_prefer_conditional_expression_over_return = true : refactoring
129 | csharp_prefer_simple_default_expression = true : suggestion
130 | csharp_style_deconstructed_variable_declaration = true : suggestion
131 |
132 | # Expression-bodied members
133 | csharp_style_expression_bodied_methods = true : refactoring
134 | csharp_style_expression_bodied_constructors = true : refactoring
135 | csharp_style_expression_bodied_operators = true : refactoring
136 | csharp_style_expression_bodied_properties = true : refactoring
137 | csharp_style_expression_bodied_indexers = true : refactoring
138 | csharp_style_expression_bodied_accessors = true : refactoring
139 | csharp_style_expression_bodied_lambdas = true : refactoring
140 | csharp_style_expression_bodied_local_functions = true : refactoring
141 |
142 | # Pattern matching
143 | csharp_style_pattern_matching_over_is_with_cast_check = true : suggestion
144 | csharp_style_pattern_matching_over_as_with_null_check = true : suggestion
145 | csharp_style_inlined_variable_declaration = true : suggestion
146 |
147 | # Null checking preferences
148 | csharp_style_throw_expression = true : suggestion
149 | csharp_style_conditional_delegate_call = true : suggestion
150 |
151 | # Other features
152 | csharp_style_prefer_index_operator = false : none
153 | csharp_style_prefer_range_operator = false : none
154 | csharp_style_pattern_local_over_anonymous_function = false : none
155 |
156 | # Space preferences
157 | csharp_space_after_cast = false
158 | csharp_space_after_colon_in_inheritance_clause = true
159 | csharp_space_after_comma = true
160 | csharp_space_after_dot = false
161 | csharp_space_after_keywords_in_control_flow_statements = true
162 | csharp_space_after_semicolon_in_for_statement = true
163 | csharp_space_around_binary_operators = before_and_after
164 | csharp_space_around_declaration_statements = do_not_ignore
165 | csharp_space_before_colon_in_inheritance_clause = true
166 | csharp_space_before_comma = false
167 | csharp_space_before_dot = false
168 | csharp_space_before_open_square_brackets = false
169 | csharp_space_before_semicolon_in_for_statement = false
170 | csharp_space_between_empty_square_brackets = false
171 | csharp_space_between_method_call_empty_parameter_list_parentheses = false
172 | csharp_space_between_method_call_name_and_opening_parenthesis = false
173 | csharp_space_between_method_call_parameter_list_parentheses = false
174 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
175 | csharp_space_between_method_declaration_name_and_open_parenthesis = false
176 | csharp_space_between_method_declaration_parameter_list_parentheses = false
177 | csharp_space_between_parentheses = false
178 | csharp_space_between_square_brackets = false
179 |
180 | # Analyzers
181 | dotnet_code_quality.ca1802.api_surface = private, internal
182 |
183 | # C++ Files
184 | [*.{cpp,h,in}]
185 | curly_bracket_next_line = true
186 | indent_brace_style = Allman
187 |
188 | # Xml project files
189 | [*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}]
190 | indent_size = 2
191 |
192 | # Xml build files
193 | [*.builds]
194 | indent_size = 2
195 |
196 | # Xml files
197 | [*.{xml,stylecop,resx,ruleset}]
198 | indent_size = 2
199 |
200 | # Xml config files
201 | [*.{props,targets,config,nuspec}]
202 | indent_size = 2
203 |
204 | # Shell scripts
205 | [*.sh]
206 | end_of_line = lf
207 | [*.{cmd, bat}]
208 | end_of_line = crlf
209 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Ll]og/
33 | [Ll]ogs/
34 |
35 | # Visual Studio 2015/2017 cache/options directory
36 | .vs/
37 | # Uncomment if you have tasks that create the project's static files in wwwroot
38 | #wwwroot/
39 |
40 | # Visual Studio 2017 auto generated files
41 | Generated\ Files/
42 |
43 | # MSTest test Results
44 | [Tt]est[Rr]esult*/
45 | [Bb]uild[Ll]og.*
46 |
47 | # NUnit
48 | *.VisualState.xml
49 | TestResult.xml
50 | nunit-*.xml
51 |
52 | # Build Results of an ATL Project
53 | [Dd]ebugPS/
54 | [Rr]eleasePS/
55 | dlldata.c
56 |
57 | # Benchmark Results
58 | BenchmarkDotNet.Artifacts/
59 |
60 | # .NET Core
61 | project.lock.json
62 | project.fragment.lock.json
63 | artifacts/
64 |
65 | # ASP.NET Scaffolding
66 | ScaffoldingReadMe.txt
67 |
68 | # StyleCop
69 | StyleCopReport.xml
70 |
71 | # Files built by Visual Studio
72 | *_i.c
73 | *_p.c
74 | *_h.h
75 | *.ilk
76 | *.meta
77 | *.obj
78 | *.iobj
79 | *.pch
80 | *.pdb
81 | *.ipdb
82 | *.pgc
83 | *.pgd
84 | *.rsp
85 | *.sbr
86 | *.tlb
87 | *.tli
88 | *.tlh
89 | *.tmp
90 | *.tmp_proj
91 | *_wpftmp.csproj
92 | *.log
93 | *.tlog
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.)
298 | *.vbp
299 |
300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project)
301 | *.dsw
302 | *.dsp
303 |
304 | # Visual Studio 6 technical files
305 | *.ncb
306 | *.aps
307 |
308 | # Visual Studio LightSwitch build output
309 | **/*.HTMLClient/GeneratedArtifacts
310 | **/*.DesktopClient/GeneratedArtifacts
311 | **/*.DesktopClient/ModelManifest.xml
312 | **/*.Server/GeneratedArtifacts
313 | **/*.Server/ModelManifest.xml
314 | _Pvt_Extensions
315 |
316 | # Paket dependency manager
317 | .paket/paket.exe
318 | paket-files/
319 |
320 | # FAKE - F# Make
321 | .fake/
322 |
323 | # CodeRush personal settings
324 | .cr/personal
325 |
326 | # Python Tools for Visual Studio (PTVS)
327 | __pycache__/
328 | *.pyc
329 |
330 | # Cake - Uncomment if you are using it
331 | # tools/**
332 | # !tools/packages.config
333 |
334 | # Tabs Studio
335 | *.tss
336 |
337 | # Telerik's JustMock configuration file
338 | *.jmconfig
339 |
340 | # BizTalk build output
341 | *.btp.cs
342 | *.btm.cs
343 | *.odx.cs
344 | *.xsd.cs
345 |
346 | # OpenCover UI analysis results
347 | OpenCover/
348 |
349 | # Azure Stream Analytics local run output
350 | ASALocalRun/
351 |
352 | # MSBuild Binary and Structured Log
353 | *.binlog
354 |
355 | # NVidia Nsight GPU debugger configuration file
356 | *.nvuser
357 |
358 | # MFractors (Xamarin productivity tool) working folder
359 | .mfractor/
360 |
361 | # Local History for Visual Studio
362 | .localhistory/
363 |
364 | # Visual Studio History (VSHistory) files
365 | .vshistory/
366 |
367 | # BeatPulse healthcheck temp database
368 | healthchecksdb
369 |
370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
371 | MigrationBackup/
372 |
373 | # Ionide (cross platform F# VS Code tools) working folder
374 | .ionide/
375 |
376 | # Fody - auto-generated XML schema
377 | FodyWeavers.xsd
378 |
379 | # VS Code files for those working on multiple tools
380 | .vscode/*
381 | !.vscode/settings.json
382 | !.vscode/tasks.json
383 | !.vscode/launch.json
384 | !.vscode/extensions.json
385 | *.code-workspace
386 |
387 | # Local History for Visual Studio Code
388 | .history/
389 |
390 | # Windows Installer files from build outputs
391 | *.cab
392 | *.msi
393 | *.msix
394 | *.msm
395 | *.msp
396 |
397 | # JetBrains Rider
398 | *.sln.iml
399 |
--------------------------------------------------------------------------------
/AvaloniaExtensions.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.12.35209.166
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{86C45239-6676-46FA-8FAD-4093EAD45427}"
7 | ProjectSection(SolutionItems) = preProject
8 | .editorconfig = .editorconfig
9 | .gitignore = .gitignore
10 | Directory.Build.props = Directory.Build.props
11 | LICENSE = LICENSE
12 | README.md = README.md
13 | README.zh-CN.md = README.zh-CN.md
14 | EndProjectSection
15 | EndProject
16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E20B2331-FE69-414C-B706-11EF41B09D8B}"
17 | EndProject
18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaExtensions.Axaml", "src\AvaloniaExtensions.Axaml\AvaloniaExtensions.Axaml.csproj", "{FBEBA881-CA18-4B65-9F32-D9C0BFF9AD7F}"
19 | EndProject
20 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{07FEB8AC-F72D-469E-8AE6-A5518919D2FD}"
21 | EndProject
22 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaExtensions.Axaml.Demo", "src\AvaloniaExtensions.Axaml.Demo\AvaloniaExtensions.Axaml.Demo.csproj", "{9354640E-E0A0-43DD-9CFC-FDDF624305DA}"
23 | EndProject
24 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.XmlTranslator.Demo", "src\Avalonia.XmlTranslator.Demo\Avalonia.XmlTranslator.Demo.csproj", "{72C8A993-523D-458F-9F1B-9487CE99222B}"
25 | EndProject
26 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaExtensions.Tests", "src\AvaloniaExtensions.Tests\AvaloniaExtensions.Tests.csproj", "{7360E627-D807-4CBD-B258-56E0BD9701C6}"
27 | EndProject
28 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaXmlTranslator", "src\AvaloniaXmlTranslator\AvaloniaXmlTranslator.csproj", "{848856E2-00C2-0F3D-6CA5-FFDF0D0FB3BE}"
29 | EndProject
30 | Global
31 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
32 | Debug|Any CPU = Debug|Any CPU
33 | Release|Any CPU = Release|Any CPU
34 | EndGlobalSection
35 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
36 | {FBEBA881-CA18-4B65-9F32-D9C0BFF9AD7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {FBEBA881-CA18-4B65-9F32-D9C0BFF9AD7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {FBEBA881-CA18-4B65-9F32-D9C0BFF9AD7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
39 | {FBEBA881-CA18-4B65-9F32-D9C0BFF9AD7F}.Release|Any CPU.Build.0 = Release|Any CPU
40 | {9354640E-E0A0-43DD-9CFC-FDDF624305DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41 | {9354640E-E0A0-43DD-9CFC-FDDF624305DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
42 | {9354640E-E0A0-43DD-9CFC-FDDF624305DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
43 | {9354640E-E0A0-43DD-9CFC-FDDF624305DA}.Release|Any CPU.Build.0 = Release|Any CPU
44 | {72C8A993-523D-458F-9F1B-9487CE99222B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45 | {72C8A993-523D-458F-9F1B-9487CE99222B}.Debug|Any CPU.Build.0 = Debug|Any CPU
46 | {72C8A993-523D-458F-9F1B-9487CE99222B}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {72C8A993-523D-458F-9F1B-9487CE99222B}.Release|Any CPU.Build.0 = Release|Any CPU
48 | {7360E627-D807-4CBD-B258-56E0BD9701C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49 | {7360E627-D807-4CBD-B258-56E0BD9701C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
50 | {7360E627-D807-4CBD-B258-56E0BD9701C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
51 | {7360E627-D807-4CBD-B258-56E0BD9701C6}.Release|Any CPU.Build.0 = Release|Any CPU
52 | {848856E2-00C2-0F3D-6CA5-FFDF0D0FB3BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53 | {848856E2-00C2-0F3D-6CA5-FFDF0D0FB3BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
54 | {848856E2-00C2-0F3D-6CA5-FFDF0D0FB3BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
55 | {848856E2-00C2-0F3D-6CA5-FFDF0D0FB3BE}.Release|Any CPU.Build.0 = Release|Any CPU
56 | EndGlobalSection
57 | GlobalSection(SolutionProperties) = preSolution
58 | HideSolutionNode = FALSE
59 | EndGlobalSection
60 | GlobalSection(NestedProjects) = preSolution
61 | {FBEBA881-CA18-4B65-9F32-D9C0BFF9AD7F} = {E20B2331-FE69-414C-B706-11EF41B09D8B}
62 | {9354640E-E0A0-43DD-9CFC-FDDF624305DA} = {07FEB8AC-F72D-469E-8AE6-A5518919D2FD}
63 | {72C8A993-523D-458F-9F1B-9487CE99222B} = {07FEB8AC-F72D-469E-8AE6-A5518919D2FD}
64 | {7360E627-D807-4CBD-B258-56E0BD9701C6} = {07FEB8AC-F72D-469E-8AE6-A5518919D2FD}
65 | {848856E2-00C2-0F3D-6CA5-FFDF0D0FB3BE} = {E20B2331-FE69-414C-B706-11EF41B09D8B}
66 | EndGlobalSection
67 | GlobalSection(ExtensibilityGlobals) = postSolution
68 | SolutionGuid = {D3B18EBC-D9A2-4625-8DD5-1BE213D6DEEA}
69 | EndGlobalSection
70 | EndGlobal
71 |
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 沙漠尽头的狼
5 | Copyright (c) 2024 https://codewf.com
6 | true
7 | MIT
8 | preview
9 | https://github.com/dotnet9/AvaloniaExtensions
10 | https://github.com/dotnet9/AvaloniaExtensions
11 | true
12 | true
13 | enable
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Dotnet9(dotnet9.com)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AvaloniaExtensions
2 |
3 | English | [简体中文](README.zh-CN.md)
4 |
5 | A syntactic sugar library that brings convenience to Avalonia UI development, aiming to enhance development efficiency and experience by providing additional functionality and simplifying common operations.
6 |
7 | ## Install
8 |
9 | ```bash
10 | Install-Package AvaloniaExtensions.Axaml
11 | ```
12 |
13 | ## I18n
14 |
15 | **Format Requirements**: Create an `I18n` directory in your project and create multilingual resource files `Resources[.xx].resx` within it as needed. For example, create `Resources.resx`, `Resources.zh-CN.resx`, and `Resources.ja-JP.resx` for English, Simplified Chinese, and Japanese. The demo structure is as follows:
16 |
17 | 
18 |
19 | It is recommended to use ResX Manager to edit resource files for easier management of multilingual resources:
20 |
21 | 
22 |
23 | You can use a T4 template file (such as `Language.tt` in the demo) to automatically generate C# code for resource keys for easy referencing in your project:
24 |
25 | ```tt
26 | <#@ template debug="false" hostspecific="true" language="C#" #>
27 | <#@ assembly name="System.Core" #>
28 | <#@ assembly name="System.Xml" #>
29 | <#@ assembly name="System.Xml.Linq" #>
30 | <#@ import namespace="System.Linq" #>
31 | <#@ import namespace="System.Text" #>
32 | <#@ import namespace="System.Collections.Generic" #>
33 | <#@ import namespace="System.Xml.Linq" #>
34 | <#@ import namespace="System.IO" #>
35 | <#@ output extension=".cs" #>
36 | //------------------------------------------------------------------------------
37 | //
38 | // This code was generated by a tool.
39 | // Changes to this file may cause incorrect behavior and will be lost if
40 | // the code is regenerated.
41 | //
42 | //------------------------------------------------------------------------------
43 | <#
44 | const string ResourceFileName = "Resources.resx";
45 | #>
46 |
47 | namespace <#=System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("NamespaceHint").ToString()#>;
48 |
49 | public static class Language
50 | {
51 | <#
52 | var resourceKeys = XElement.Load(this.Host.ResolvePath(ResourceFileName))
53 | .Elements("data")
54 | .Select(item => item.Attribute("name")?.Value)
55 | .Where(item => item != null);
56 |
57 | var resourceDesignerName = Path.GetFileNameWithoutExtension(ResourceFileName);
58 |
59 | foreach (string resourceKey in resourceKeys)
60 | {
61 | #>
62 | public static readonly string <#= resourceKey #> = "<#= resourceKey #>";
63 | <#
64 | }
65 | #>
66 | }
67 | ```
68 |
69 | Generated C# code example:
70 |
71 | ```csharp
72 | public static class Language
73 | {
74 | public static readonly string AppName = "AppName";
75 | public static readonly string Welcome = "Welcome";
76 | }
77 | ```
78 |
79 | **Usage**:
80 |
81 | - Static binding of resource keys:
82 |
83 | ```axaml
84 |
85 |
86 | ```
87 |
88 | - Dynamic binding of resource keys:
89 |
90 | ```axaml
91 |
92 | ```
93 |
94 | - Switching languages:
95 |
96 | ```csharp
97 | I18nManager.Instance.Culture = new CultureInfo(language);
98 | ```
99 |
100 | ## If
101 |
102 | Using the Conditional expression in AXAML.
103 |
104 | ```axaml
105 |
106 |
107 | ```
108 |
109 | ## Converter Extensions
110 |
111 | ### IfConditionConverter
112 |
113 | ```axaml
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 | ```
123 |
124 | ```axaml
125 |
126 | ```
127 |
128 | ## Thanks
129 |
130 | Taken from open source, contributed to open source. The development of this library was inspired and aided by the following open-source projects or articles:
131 |
132 | - WpfExtensions: [https://github.com/DingpingZhang/WpfExtensions](https://github.com/DingpingZhang/WpfExtensions)
133 | - I18N:[https://github.com/Antelcat/I18N](https://github.com/Antelcat/I18N)
134 | - WPF或Avalonia使用tt模板和resx文件实现国际化:[https://blog.csdn.net/eyupaopao/article/details/136638194](https://blog.csdn.net/eyupaopao/article/details/136638194)
135 |
136 | Special thanks to the contributors of these projects. Their efforts have provided valuable references and assistance for the development of AvaloniaExtensions.
137 |
--------------------------------------------------------------------------------
/README.zh-CN.md:
--------------------------------------------------------------------------------
1 | # AvaloniaExtensions
2 |
3 | 简体中文 | [English](README.md)
4 |
5 | 为Avalonia UI开发带来便利的语法糖库,旨在通过提供额外的功能和简化常用操作,提升开发效率与体验。
6 |
7 | ## 安装
8 |
9 | ```bash
10 | Install-Package AvaloniaExtensions.Axaml
11 | ```
12 |
13 | ## I18n
14 |
15 | **格式要求**: 在项目中创建`I18n`目录,并在其中创建需要支持的多语言资源文件`Resources[.xx].resx`。例如,为英语、简体中文、日语创建`Resources.resx`和`Resources.zh-CN.resx`、`Resources.ja-JP.resx`。参考Demo结构如下:
16 |
17 | 
18 |
19 | 推荐使用ResX Manager进行资源文件编辑,以更便捷地管理多语言资源:
20 |
21 | 
22 |
23 | 可使用T4模板文件(如Demo中的`Language.tt`)自动生成资源键的C#代码,以便在项目中引用:
24 |
25 | ```tt
26 | <#@ template debug="false" hostspecific="true" language="C#" #>
27 | <#@ assembly name="System.Core" #>
28 | <#@ assembly name="System.Xml" #>
29 | <#@ assembly name="System.Xml.Linq" #>
30 | <#@ import namespace="System.Linq" #>
31 | <#@ import namespace="System.Text" #>
32 | <#@ import namespace="System.Collections.Generic" #>
33 | <#@ import namespace="System.Xml.Linq" #>
34 | <#@ import namespace="System.IO" #>
35 | <#@ output extension=".cs" #>
36 | //------------------------------------------------------------------------------
37 | //
38 | // This code was generated by a tool.
39 | // Changes to this file may cause incorrect behavior and will be lost if
40 | // the code is regenerated.
41 | //
42 | //------------------------------------------------------------------------------
43 | <#
44 | const string ResourceFileName = "Resources.resx";
45 | #>
46 |
47 | namespace <#=System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("NamespaceHint").ToString()#>;
48 |
49 | public static class Language
50 | {
51 | <#
52 | var resourceKeys = XElement.Load(this.Host.ResolvePath(ResourceFileName))
53 | .Elements("data")
54 | .Select(item => item.Attribute("name")?.Value)
55 | .Where(item => item != null);
56 |
57 | var resourceDesignerName = Path.GetFileNameWithoutExtension(ResourceFileName);
58 |
59 | foreach (string resourceKey in resourceKeys)
60 | {
61 | #>
62 | public static readonly string <#= resourceKey #> = "<#= resourceKey #>";
63 | <#
64 | }
65 | #>
66 | }
67 | ```
68 |
69 | 生成的C#代码示例:
70 |
71 | ```csharp
72 | public static class Language
73 | {
74 | public static readonly string AppName = "AppName";
75 | public static readonly string Welcome = "Welcome";
76 | }
77 | ```
78 |
79 | **使用方式**:
80 |
81 | - 静态绑定资源键:
82 |
83 | ```axaml
84 |
85 |
86 |
87 | ```
88 |
89 | - 动态绑定资源键:
90 |
91 | ```axaml
92 |
93 | ```
94 |
95 | - 切换语言:
96 |
97 | ```csharp
98 | I18nManager.Instance.Culture = new CultureInfo(language);
99 | ```
100 |
101 | ## If
102 |
103 | 在AXAML中使用条件表达式
104 |
105 | ```axaml
106 |
107 |
108 | ```
109 |
110 | ## 扩展转换器
111 |
112 | ### IfConditionConverter
113 |
114 | ```axaml
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 | ```
124 |
125 | ```axaml
126 |
127 | ```
128 |
129 | ## 感谢
130 |
131 | 取之于开源,献之于开源。本库的开发受到了以下开源项目或文章的启发与帮助:
132 |
133 | - WpfExtensions: [https://github.com/DingpingZhang/WpfExtensions](https://github.com/DingpingZhang/WpfExtensions)
134 | - I18N:[https://github.com/Antelcat/I18N](https://github.com/Antelcat/I18N)
135 | - WPF或Avalonia使用tt模板和resx文件实现国际化:[https://blog.csdn.net/eyupaopao/article/details/136638194](https://blog.csdn.net/eyupaopao/article/details/136638194)
136 |
137 | 特别感谢这些项目的贡献者,他们的努力为AvaloniaExtensions的开发提供了宝贵的参考与帮助。
138 |
--------------------------------------------------------------------------------
/avalonia-using-xml-files-for-internationalization.md:
--------------------------------------------------------------------------------
1 | ## 1. XML 实现 Avalonia UI 国际化的优势剖析
2 |
3 | 在软件开发日益全球化的今天,Avalonia 的国际化实现策略成为了众多开发者关注的焦点。继上一篇 [Avalonia 国际化之路:Resx 资源文件的深度应用与探索](https://dotnet9.com/bbs/post/2024/12/avalonia-internationalization-depth-application-and-exploration-of-resx-resource-files)之后,本文将引领大家深入探究如何运用自定义 XML 文件来达成 Avalonia 国际化的目标,开启一段全新的技术探索之旅。
4 |
5 |
6 | ### 1.1. 突破维护局限,拥抱用户定制
7 |
8 | Resx 资源文件往往将维护权限局限于开发端,而自定义 XML 语言文件则以其独特的灵活性脱颖而出。它能够与可执行程序一同输出,这一特性为用户侧的语言文件修改开辟了广阔的空间。用户不仅可以根据自身需求对已有语言内容进行调整,还能够轻松地扩展更多语言种类,使软件的国际化适应能力得到极大的提升,真正实现了从开发主导到用户参与的转变。
9 |
10 | ### 1.2. 命名空间加持,结构清晰有序
11 |
12 | 自定义 XML 文件采用命名空间的方式来组织语言内容,这一设计理念与类的结构形成了精准的对应关系。通过这种方式,整个翻译文件的架构变得清晰明了,易于管理与维护。无论是在大型项目中进行团队协作开发,还是在后期的代码维护与升级过程中,都能够显著提高工作效率,减少因结构混乱而可能引发的错误与困扰。
13 |
14 | ### 1.3. AI 翻译便捷,助力语言转换
15 |
16 | 在当今人工智能蓬勃发展的时代,XML 文件在 AI 翻译方面展现出了得天独厚的优势。借助特定的工具或平台,我们可以方便地利用 AI 技术对 XML 翻译文件进行处理。例如,只需提供简单的提示词,就能快速获取多种语言版本的翻译结果,为跨语言交流与软件全球化推广提供了强有力的支持。
17 |
18 | 下图为输出的XML语言文件:
19 |
20 | 
21 |
22 | ## 2. XML 文件的创建与架构设计
23 | ### 2.1. 精心规划语言文件夹
24 |
25 | 首先,我们需要创建一个专门用于存放语言文件的文件夹,例如命名为 “i18n”。在这个过程中,需要特别注意的是,相同输出路径下不同模块的 XML 文件名必须保持唯一性。因为在程序编译输出时,如果存在同名的 XML 文件,将会导致文件替换,进而造成语言信息的丢失,这无疑会给国际化进程带来严重的阻碍。
26 |
27 | 文件前缀可以工程名命名(方便区分),后缀为语言文化名
28 |
29 | 以下是创建语言文件夹后的工程结构示例图:
30 |
31 | 
32 |
33 | 编译输出后文件列表如下:
34 |
35 | ```shell
36 | AIModule.en-US.xml
37 | AIModule.ja-JP.xml
38 | AIModule.zh-CN.xml
39 | AIModule.zh-Hant.xml
40 | ConverterModule.en-US.xml
41 | ConverterModule.ja-JP.xml
42 | ConverterModule.zh-CN.xml
43 | ConverterModule.zh-Hant.xml
44 | DevelopmentModule.en-US.xml
45 | DevelopmentModule.ja-JP.xml
46 | DevelopmentModule.zh-CN.xml
47 | DevelopmentModule.zh-Hant.xml
48 | MainModule.en-US.xml
49 | MainModule.ja-JP.xml
50 | MainModule.zh-CN.xml
51 | MainModule.zh-Hant.xml
52 | XmlTranslatorManagerModule.en-US.xml
53 | XmlTranslatorManagerModule.ja-JP.xml
54 | XmlTranslatorManagerModule.zh-CN.xml
55 | XmlTranslatorManagerModule.zh-Hant.xml
56 | ```
57 |
58 | ### 2.2. 严谨构建 XML 文件内容
59 |
60 | 以下是上面一个XML文件内容(`AIModule.zh-CN.xml`):
61 |
62 | ```xml
63 |
64 |
65 |
66 |
67 | AI
68 |
69 |
70 | 智能问答助手
71 | 一键提问,即刻获取答案,智能问答助手为您解惑。
72 |
73 |
74 | AI一键多语种翻译神器
75 | 轻松实现一键翻译,支持多种语言互译,让沟通无界限!
76 |
77 |
78 | AI一键转URL Slug
79 | 轻松将中文、英文等文章标题一键转换成英文URL Slug。
80 |
81 |
82 | 语言
83 | 可选择的
84 | 已选择
85 |
86 |
87 | ```
88 |
89 | XML 文件的内容结构遵循一定的规范与层次。推荐采用三层结构来组织信息:
90 |
91 | #### 2.2.1. 第一层:Localization 节点
92 |
93 | 此节点包含三个重要的子属性:
94 | - **language**:用于明确指定语言的名称,例如 “Chinese (Simplified)” 表示简体中文。
95 | - **description**:对该语言的简要描述,如 “中文简体”,以便于开发者和用户快速了解语言的基本特征。
96 | - **cultureName**:语言的文化名,这是一个在国际化处理中非常关键的标识,例如 “zh-CN” 代表简体中文的文化区域。如果对文化名不太清楚,可以通过百度搜索等方式获取准确信息。
97 |
98 | 以下是一个基本的 XML 文件框架示例:
99 |
100 | ```xml
101 |
102 |
103 |
104 |
105 |
106 | ```
107 |
108 | #### 2.2.2. 第二层:功能名或类名节点
109 |
110 | 这一层以功能名或类名来命名节点,其目的在于对翻译文件进行有效的功能归类。例如,在一个包含 AI 模块、转换模块等的项目中,可以分别创建 “AIModule”、“ConverterModule” 等节点,将与各个模块相关的翻译内容分别放置在对应的节点下,使整个文件的结构更加清晰,便于管理与查找。
111 |
112 | 以下是一个包含多个模块节点的 XML 文件示例:
113 |
114 | ```xml
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 | ```
126 |
127 | #### 2.2.3. 第三层:语言 Key 节点
128 |
129 | 最后一层为语言 Key 节点,这些节点直接存储了具体的翻译文本内容。例如:
130 |
131 | ```xml
132 |
133 |
134 |
135 |
136 | AI
137 |
138 |
139 | 智能问答助手
140 | 一键提问,即刻获取答案,智能问答助手为您解惑。
141 |
142 |
143 | ```
144 |
145 | 在实际应用中,虽然推荐采用三层结构,但 XML 节点的嵌套层数并没有严格的限制,开发者可以根据项目的实际需求和复杂程度进行灵活调整。例如:
146 |
147 | ```xml
148 |
149 |
150 |
151 |
152 | AI
153 |
154 |
155 |
156 | 智能问答助手
157 | 一键提问,即刻获取答案,智能问答助手为您解惑。
158 |
159 |
160 |
161 |
162 |
163 | AI一键多语种翻译神器
164 | 轻松实现一键翻译,支持多种语言互译,让沟通无界限!
165 |
166 |
167 |
168 |
169 | AI一键多语种翻译神器
170 | 轻松实现一键翻译,支持多种语言互译,让沟通无界限!
171 |
172 |
173 |
174 |
175 | ```
176 |
177 | ## 3. 语言文件的强类型生成策略
178 |
179 | 为了在代码中更加方便、高效地使用 XML 翻译文件,我们采用 T4 文件将 XML 转换为 C# 的强类型。具体操作如下:
180 |
181 | 在 “i18n” 目录下创建一个 T4 文件,例如命名为 “Language.tt”,并在其中填入以下代码:
182 |
183 | ```csharp
184 | <#@ template debug="false" hostspecific="true" language="C#" #>
185 | <#@ assembly name="System.Core" #>
186 | <#@ assembly name="System.Xml" #>
187 | <#@ assembly name="System.Xml.Linq" #>
188 | <#@ import namespace="System.Linq" #>
189 | <#@ import namespace="System.Text" #>
190 | <#@ import namespace="System.Collections.Generic" #>
191 | <#@ import namespace="System.Xml.Linq" #>
192 | <#@ import namespace="System.IO" #>
193 | <#@ output extension=".cs" #>
194 | //------------------------------------------------------------------------------
195 | //
196 | // This code was generated by a tool.
197 | // Changes to this file may cause incorrect behavior and will be lost if
198 | // the code is regenerated.
199 | //
200 | //------------------------------------------------------------------------------
201 | <#
202 | string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);
203 | string xmlFilePath = Directory.GetFiles(templateDirectory, "*.xml").FirstOrDefault();
204 | if (xmlFilePath!= null)
205 | {
206 | XDocument xdoc = XDocument.Load(xmlFilePath);
207 | var classNodes = xdoc.Nodes().OfType().DescendantsAndSelf().Where(e => e.Descendants().Count() == 0).Select(e => e.Parent).Distinct().ToList();
208 | foreach (var classNode in classNodes)
209 | {
210 | var namespaceSegments = classNode.Ancestors().Reverse().Select(node => node.Name.LocalName);
211 | string namespaceName = string.Join(".", namespaceSegments);
212 | GenerateClasses(classNode, namespaceName);
213 | }
214 | }
215 | else
216 | {
217 | Write("XML file not found, please ensure that there is an XML file in the current directory");
218 | }
219 |
220 | void GenerateClasses(XElement element, string namespaceName)
221 | {
222 | string className = element.Name.LocalName;
223 | StringBuilder classBuilder = new StringBuilder();
224 | classBuilder.AppendLine($"namespace {namespaceName}");
225 | classBuilder.AppendLine("{");
226 | classBuilder.AppendLine($" public static class {className}");
227 | classBuilder.AppendLine(" {");
228 | var fieldNodes = element.Elements();
229 | foreach (var fieldNode in fieldNodes)
230 | {
231 | var propertyName = fieldNode.Name.LocalName;
232 | var languageKey = $"{namespaceName}.{className}.{propertyName}";
233 | classBuilder.AppendLine($" public static readonly string {propertyName} = \"{languageKey}\";");
234 | }
235 | classBuilder.AppendLine(" }");
236 | classBuilder.AppendLine("}");
237 | Write(classBuilder.ToString());
238 | }
239 | #>
240 | ```
241 |
242 | 每次对 XML 文件进行修改后,只需打开该 T4 文件并执行一次保存操作,系统将会自动生成或更新对应的 C# 类。例如:
243 |
244 | ```csharp
245 | //...
246 | namespace Localization
247 | {
248 | public static class AIModule
249 | {
250 | public static readonly string Title = "Localization.AIModule.Title";
251 | }
252 | }
253 | namespace Localization
254 | {
255 | public static class AskBotView
256 | {
257 | public static readonly string Title = "Localization.AskBotView.Title";
258 | public static readonly string Description = "Localization.AskBotView.Description";
259 | }
260 | }
261 | //...
262 | ```
263 |
264 | 这些生成的强类型类将为我们在后续的代码编写中提供极大的便利,使我们能够更加准确、便捷地获取和使用翻译文本。
265 |
266 | ## 4. XML 文件在 Avalonia 中的具体应用实践
267 |
268 | ### 4.1. 安装必备 NuGet 包
269 |
270 | ```shell
271 | Install-Package AvaloniaXmlTranslator
272 | ```
273 |
274 | 这一步骤将为我们的项目引入必要的功能组件,为后续的国际化操作奠定基础。
275 |
276 | ### 4.2. 动态获取语言列表
277 |
278 | 在 Avalonia 应用中,动态获取程序配置的语言列表是实现国际化界面切换的关键步骤之一。通过以下代码,我们可以轻松地获取语言列表:
279 |
280 | ```csharp
281 | List languages = I18nManager.Instance.Resources.Select(kvp => kvp.Value).ToList();
282 | ```
283 |
284 | 其中,“LocalizationLanguage” 类定义如下:
285 |
286 | ```csharp
287 | public class LocalizationLanguage
288 | {
289 | public string Language { get; set; } = (string) null;
290 |
291 | public string Description { get; set; } = (string) null;
292 |
293 | public string CultureName { get; set; } = (string) null;
294 |
295 | //...
296 | }
297 | ```
298 |
299 | 获取到语言列表后,我们可以将其用于界面绑定,例如在下拉菜单中显示可供用户选择的语言选项,或者在其他需要展示语言信息的界面元素中进行数据绑定。
300 |
301 | ### 4.3. 动态切换语言
302 |
303 | 当用户在界面中选择了不同的语言后,我们需要在代码中实现语言的动态切换。以下是实现语言切换的代码示例:
304 |
305 | ```csharp
306 | var culture = new CultureInfo(language);
307 | I18nManager.Instance.Culture = culture;
308 | ```
309 |
310 | 这里的 “language” 参数为 “LocalizationLanguage” 类的 “CultureName” 属性值,通过设置当前线程的文化信息,我们可以实现界面语言的即时切换,为用户提供无缝的国际化体验。
311 |
312 | ### 4.4. 代码中使用翻译字符串
313 |
314 | 在代码中,我们可以根据强类型 Key 方便地获取当前语言文化的翻译字符串。例如:
315 |
316 | ```csharp
317 | var title = I18nManager.GetString(Localization.AskBotView.Title); // 获取当前语言
318 | var titleZhCN = I18nManager.Instance.GetResource(Localization.Main.MainView.Title, "zh-CN"); // 获取中文简体
319 | var titleEnUS = I18nManager.Instance.GetResource(Localization.Main.MainView.Title, "en-US"); // 获取英文
320 | ```
321 |
322 | 通过这种方式,我们可以在代码的任何地方灵活地使用翻译文本,确保界面显示的内容与用户选择的语言相匹配。
323 |
324 | 下面是代码中绑定使用:
325 |
326 | ```csharp
327 | //...
328 | var header = item is UserControl { DataContext: ITabItemBase tabItem }
329 | ? tabItem.TitleKey
330 | : item?.GetType().ToString();
331 | var newTabItem = new TabItem { Content = item };
332 | newTabItem.Bind(TabItem.HeaderProperty, new I18nBinding(header));
333 | regionTarget.Items.Add(newTabItem);
334 | //...
335 | ```
336 |
337 | ### 4.5. Axaml 界面中的应用
338 |
339 | 在 Axaml 界面中使用 XML 翻译文件也非常便捷。首先,需要引入相应的命名空间:
340 |
341 | ```xaml
342 | xmlns:language="clr-namespace:Localization"
343 | xmlns:markup="https://codewf.com"
344 | ```
345 |
346 | 其中,“markup” 为前面安装的辅助库命名空间,它提供了 “I18n” 标记扩展帮助类,用于在界面中绑定翻译文本;“language” 为 T4 文件生成的 C# 强类型语言 Key 关联类命名空间,通过它可以与 XML 语言文件的语言 Key 进行关联。
347 |
348 | 以下是在控件中使用翻译文本的示例:
349 |
350 | ```xaml
351 |
359 | ```
360 |
361 | 在上述示例中,“Button” 控件的 “Content” 属性通过 “I18n” 标记扩展绑定到了 “ChoiceLanguagesView.LanguageKey” 对应的翻译文本上。这样,当界面语言发生变化时,按钮的显示文本也会自动更新为相应语言的翻译内容。
362 |
363 | 当然也支持指定语言:
364 |
365 | ```xaml
366 |
367 |
368 |
369 |
370 |
371 | ```
372 |
373 | 此外,Axaml 界面还支持动态 Key 的绑定,例如:
374 |
375 | ```xaml
376 |
381 | ```
382 |
383 | 在这个示例中,“Banner” 控件的 “Content” 和 “Header” 属性分别绑定到了动态的 “SelectedMenuItem.Description” 和 “SelectedMenuItem.Name” 属性上,通过 “I18n” 标记扩展实现了动态翻译文本的显示。
384 |
385 | ## 5. 语言管理功能的深度解析
386 |
387 | 为了更好地管理 XML 语言文件,站长开发了部分管理功能,包括多模块 XML 文件合并与 XML 文件编辑,可点击下载 [管理工具](https://github.com/dotnet9/CodeWF.Toolbox/releases/tag/1.0.1)或自行编译 [工具源码](https://github.com/dotnet9/CodeWF.Toolbox),工具程序结构如下:
388 |
389 | 
390 |
391 | ### 5.1. 多模块XML文件合并
392 |
393 | 运行工具箱后,选择 “XML 国际化管理” 下的 “XML 多模块文件合并” 节点。默认情况下,将会打开工具箱自己的 “I18n” 目录(点击 “A” 可选择其他语言目录)。在界面的左侧,将会显示 XML 文件列表,点击文件即可浏览其详细内容。
394 |
395 | 
396 |
397 | 在 “B” 处输入合并后的 XML 文件前缀,默认值为 “Localization”。然后,点击 “C” 按钮即可执行文件合并操作。以下是合并后的效果示例图:
398 |
399 | 
400 |
401 | 在进行多模块 XML 文件合并时,需要特别注意以下几点:
402 |
403 | 1. 合并前务必进行数据备份,以防止因合并操作失误而导致数据丢失或损坏。
404 | 2. 建议在合并前确保每个 XML 根节点相同,例如都命名为 “Localization”,这样可以保证合并后的文件结构更加规范和统一。
405 | 3. 不同模块的 XML 节点应避免重复,否则可能会在合并过程中出现数据冲突或覆盖的问题。
406 |
407 | 多模块 XML 文件合并的原理其实非常简单,即将相同语言后缀下的 XML 文件合并到一个根节点下,从而实现语言数据的整合与集中管理。
408 |
409 | ### 5.2. XML 文件编辑
410 |
411 | 目前,XML 文件编辑功能相对较为基础,仅支持对现有的语言进行修改。
412 |
413 | 
414 |
415 | 在后续的开发计划中,站长将进一步完善 XML 文件编辑功能,预计将会支持以下操作:
416 |
417 | 1. 可修改 Key:允许用户对已有的语言 Key 进行修改,以适应项目需求的变化或修正错误的 Key 命名。
418 | 2. 可添加 Key、删除 Key:提供灵活的 Key 管理功能,用户可以根据实际需要添加新的语言 Key 或删除不再使用的 Key,使 XML 文件的内容更加精准和高效。
419 | 3. 可添加语言、删除语言:除了对 Key 的管理外,还将支持添加新的语言种类以及删除不再需要的语言,进一步拓展 XML 文件的国际化支持范围。
420 | 4. 一键翻译:借助先进的 AI 翻译技术,实现一键将 XML 文件中的内容翻译成多种语言,大大提高翻译效率,减少人工翻译的工作量和成本。
421 |
422 | ### 5.3. AI 翻译的巧妙应用
423 |
424 | 在 XML 文件的翻译过程中,我们可以巧妙地利用 AI 翻译技术来提高效率。例如,通过编写如下提示词:
425 |
426 | ````markdown
427 | 帮我将以下的中文简体XML翻译文件再翻译成中文繁体、英文、日语3个版本,不用回复其他文字,谢谢:
428 |
429 | ```xml
430 |
431 |
432 |
433 |
434 | 码界工坊工具箱
435 | 搜你所想
436 | 联系微信号:codewf
437 | 关注微信公众号:Dotnet9
438 | 想要的都有,没有请告知。
439 | 访问在线工具箱
440 |
441 | 关于
442 | 本项目只用于学习使用
443 |
444 |
445 | ```
446 | ````
447 |
448 | 将上述 XML 内容提供给 AI,即可获取相应的中文繁体、英文、日语翻译版本,为国际化工作提供了快速且便捷的翻译途径,效果显著,如同以下示例图展示:
449 |
450 | 
451 |
452 | ## 6. 总结与展望
453 |
454 | 在 Avalonia 国际化的征程中,Resx 资源文件和自定义 XML 文件是两种重要的实现方式,开发者应根据具体需求进行合理选择。
455 |
456 | ### 6.1. Resx 资源文件的适用场景
457 |
458 | 1. 当项目无用户侧修改需求时,Resx 资源文件凭借其在开发环境中的便捷管理性,可通过 Resx Manager 等工具进行高效操作,是较为理想的选择。
459 | 2. 对于那些注重开发过程中资源文件管理效率,且不需要用户参与语言内容调整的项目,Resx 资源文件能够很好地满足需求,确保项目的国际化进程顺利推进。
460 |
461 | ### 6.2. 自定义 XML 文件的优势领域
462 |
463 | 1. 若项目存在用户侧修改需求,自定义 XML 文件则能够大放异彩。它允许用户根据自身使用场景和语言习惯对软件的语言内容进行灵活调整,极大地提升了用户体验和软件的适应性。
464 | 2. 在需要借助 AI 编辑进行语言处理的情况下,XML 文件的格式更易于与 AI 工具进行交互,能够充分利用 AI 技术的优势,实现高效的翻译和语言管理。
465 | 3. 对于追求清晰、有序的语言结构管理,以便于团队协作、代码维护和项目扩展的项目,自定义 XML 文件的命名空间组织方式和灵活的节点结构能够提供强有力的支持。
466 |
467 | 本文详细阐述了 Avalonia 使用自定义 XML 文件实现国际化的全过程,包括 XML 文件的创建、强类型生成、在 Avalonia 中的具体应用以及语言管理功能等方面。同时,为开发者提供了丰富的代码示例、详细的操作步骤以及相关的图片说明,旨在帮助开发者快速上手并熟练运用这一国际化方案。文中涉及的相关资源如下:
468 |
469 | - XML语言管理包:[AvaloniaXmlTranslator](https://github.com/dotnet9/AvaloniaExtensions/tree/main/src/AvaloniaXmlTranslator)
470 | - 案例Demo及语言管理工具:[CodeWF.Toolbox](https://github.com/dotnet9/CodeWF.Toolbox/tree/develop)
471 | - Resx资源管理扩展:[Resx Manager](https://marketplace.visualstudio.com/items?itemName=TomEnglert.ResXManager)
472 |
473 | 展望未来,随着技术的不断发展和应用场景的日益丰富,Avalonia 国际化的实现方式也将不断演进和完善。我们期待能够看到更多便捷、高效的工具和技术涌现,进一步简化国际化开发流程,提升软件的全球化品质,为用户带来更加卓越的跨语言使用体验。无论是 Resx 资源文件还是自定义 XML 文件,都将在各自的适用领域继续发挥重要作用,共同推动 Avalonia 国际化进程的不断前进。
474 |
--------------------------------------------------------------------------------
/doc/imgs/ResourceConfig.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotnet9/AvaloniaExtensions/77d4e75175693536fae5abc0664524b53d6648ac/doc/imgs/ResourceConfig.png
--------------------------------------------------------------------------------
/doc/imgs/ResourceDir.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotnet9/AvaloniaExtensions/77d4e75175693536fae5abc0664524b53d6648ac/doc/imgs/ResourceDir.png
--------------------------------------------------------------------------------
/logo.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotnet9/AvaloniaExtensions/77d4e75175693536fae5abc0664524b53d6648ac/logo.ico
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotnet9/AvaloniaExtensions/77d4e75175693536fae5abc0664524b53d6648ac/logo.png
--------------------------------------------------------------------------------
/src/Avalonia.XmlTranslator.Demo/App.axaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/Avalonia.XmlTranslator.Demo/App.axaml.cs:
--------------------------------------------------------------------------------
1 | using System.Globalization;
2 | using Avalonia.Controls.ApplicationLifetimes;
3 | using Avalonia.Markup.Xaml;
4 | using Avalonia.XmlTranslator.Demo.ViewModels;
5 | using Avalonia.XmlTranslator.Demo.Views;
6 | using AvaloniaXmlTranslator;
7 | using Prism.DryIoc;
8 | using Prism.Ioc;
9 |
10 | namespace Avalonia.XmlTranslator.Demo;
11 |
12 | public partial class App : PrismApplication
13 | {
14 | public override void Initialize()
15 | {
16 | AvaloniaXamlLoader.Load(this);
17 | I18nManager.Instance.Culture = new CultureInfo("zh-CN");
18 | base.Initialize(); // <-- Required
19 | }
20 |
21 | public override void OnFrameworkInitializationCompleted()
22 | {
23 | if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
24 | {
25 | desktop.MainWindow = new MainWindow { DataContext = new MainWindowViewModel() };
26 | }
27 |
28 | base.OnFrameworkInitializationCompleted();
29 | }
30 |
31 | protected override AvaloniaObject CreateShell()
32 | {
33 | return Container.Resolve();
34 | }
35 |
36 | protected override void RegisterTypes(IContainerRegistry containerRegistry)
37 | {
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Avalonia.XmlTranslator.Demo/Avalonia.XmlTranslator.Demo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | WinExe
4 | net9.0;net9.0-windows;net10.0;net10.0-windows
5 | enable
6 | true
7 | true
8 | app.manifest
9 | true
10 |
11 |
12 | true
13 | true
14 |
15 |
16 | true
17 | true
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | PreserveNewest
48 |
49 |
50 | PreserveNewest
51 |
52 |
53 | TextTemplatingFileGenerator
54 | Language.cs
55 |
56 |
57 | PreserveNewest
58 |
59 |
60 | PreserveNewest
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | True
71 | True
72 | Language.tt
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/src/Avalonia.XmlTranslator.Demo/I18n/Language.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Changes to this file may cause incorrect behavior and will be lost if
5 | // the code is regenerated.
6 | //
7 | //------------------------------------------------------------------------------
8 | namespace Localization.Main
9 | {
10 | public static class MainView
11 | {
12 | public static readonly string Title = "Localization.Main.MainView.Title";
13 | public static readonly string RunningCountInfo = "Localization.Main.MainView.RunningCountInfo";
14 | public static readonly string CurrentTimeFormat = "Localization.Main.MainView.CurrentTimeFormat";
15 | public static readonly string ChangeLanguage = "Localization.Main.MainView.ChangeLanguage";
16 | public static readonly string Exit = "Localization.Main.MainView.Exit";
17 | }
18 | }
19 | namespace Localization.Main
20 | {
21 | public static class SettingView
22 | {
23 | public static readonly string Title = "Localization.Main.SettingView.Title";
24 | public static readonly string NoPrompt = "Localization.Main.SettingView.NoPrompt";
25 | }
26 | }
27 | namespace Localization.DevelopModule
28 | {
29 | public static class Title2SlugView
30 | {
31 | public static readonly string Title = "Localization.DevelopModule.Title2SlugView.Title";
32 | public static readonly string Convert = "Localization.DevelopModule.Title2SlugView.Convert";
33 | }
34 | }
35 | namespace Localization.DevelopModule
36 | {
37 | public static class SettingView
38 | {
39 | public static readonly string Title = "Localization.DevelopModule.SettingView.Title";
40 | public static readonly string MaxLength = "Localization.DevelopModule.SettingView.MaxLength";
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Avalonia.XmlTranslator.Demo/I18n/Language.tt:
--------------------------------------------------------------------------------
1 | <#@ template debug="false" hostspecific="true" language="C#" #>
2 | <#@ assembly name="System.Core" #>
3 | <#@ assembly name="System.Xml" #>
4 | <#@ assembly name="System.Xml.Linq" #>
5 | <#@ import namespace="System.Linq" #>
6 | <#@ import namespace="System.Text" #>
7 | <#@ import namespace="System.Collections.Generic" #>
8 | <#@ import namespace="System.Xml.Linq" #>
9 | <#@ import namespace="System.IO" #>
10 | <#@ output extension=".cs" #>
11 | //------------------------------------------------------------------------------
12 | //
13 | // This code was generated by a tool.
14 | // Changes to this file may cause incorrect behavior and will be lost if
15 | // the code is regenerated.
16 | //
17 | //------------------------------------------------------------------------------
18 | <#
19 | string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);
20 | string xmlFilePath = Directory.GetFiles(templateDirectory, "*.xml").FirstOrDefault();
21 | if (xmlFilePath!= null)
22 | {
23 | XDocument xdoc = XDocument.Load(xmlFilePath);
24 | var classNodes = xdoc.Nodes().OfType().DescendantsAndSelf().Where(e => e.Descendants().Count() == 0).Select(e => e.Parent).Distinct().ToList();
25 | foreach (var classNode in classNodes)
26 | {
27 | var namespaceSegments = classNode.Ancestors().Reverse().Select(node => node.Name.LocalName);
28 | string namespaceName = string.Join(".", namespaceSegments);
29 | GenerateClasses(classNode, namespaceName);
30 | }
31 | }
32 | else
33 | {
34 | Write("XML file not found, please ensure that there is an XML file in the current directory");
35 | }
36 |
37 | void GenerateClasses(XElement element, string namespaceName)
38 | {
39 | string className = element.Name.LocalName;
40 | StringBuilder classBuilder = new StringBuilder();
41 | classBuilder.AppendLine($"namespace {namespaceName}");
42 | classBuilder.AppendLine("{");
43 | classBuilder.AppendLine($" public static class {className}");
44 | classBuilder.AppendLine(" {");
45 | var fieldNodes = element.Elements();
46 | foreach (var fieldNode in fieldNodes)
47 | {
48 | var propertyName = fieldNode.Name.LocalName;
49 | var languageKey = $"{namespaceName}.{className}.{propertyName}";
50 | classBuilder.AppendLine($" public static readonly string {propertyName} = \"{languageKey}\";");
51 | }
52 | classBuilder.AppendLine(" }");
53 | classBuilder.AppendLine("}");
54 | Write(classBuilder.ToString());
55 | }
56 | #>
57 |
--------------------------------------------------------------------------------
/src/Avalonia.XmlTranslator.Demo/I18n/en-US.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Implement internationalization using XML
7 | Running {0} operating system, {1}
8 | The current time is {0}
9 | Switch language
10 | Exit the program
11 |
12 |
13 | Settings
14 | Don't prompt again
15 |
16 |
17 |
18 |
19 | Convert article title to URL slug
20 | Convert
21 |
22 |
23 | Settings
24 | Maximum length
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/Avalonia.XmlTranslator.Demo/I18n/ja-JP.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | XMLを使って国際化を実現する
7 | 実行中 {0} オペレーティングシステム,{1}
8 | 現在の時間は {0} です。
9 | 言語の切り替え
10 | プログラムを終了する
11 |
12 |
13 | 設定
14 | もうメッセージを表示しない
15 |
16 |
17 |
18 |
19 | 記事のタイトルをURLのエイリアスに変換する
20 | 変換する
21 |
22 |
23 | 設定
24 | 最大長さ
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/Avalonia.XmlTranslator.Demo/I18n/zh-CN.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 使用XML实现国际化
7 | 正在运行 {0} 操作系统,{1}
8 | 当前时间是 {0}
9 | 切换语言
10 | 退出程序
11 |
12 |
13 | 设置
14 | 不再提示
15 |
16 |
17 |
18 |
19 | 文章标题转URL别名
20 | 转换
21 |
22 |
23 | 设置
24 | 最大长度
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/Avalonia.XmlTranslator.Demo/I18n/zh-Hant.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 使用XML實現國際化
7 | 正在運行 {0} 作業系統,{1}
8 | 當前時間是 {0}
9 | 切換語言
10 | 退出程式
11 |
12 |
13 | 設定
14 | 不再提示
15 |
16 |
17 |
18 |
19 | 文章標題轉換為URL別名
20 | 轉換
21 |
22 |
23 | 設定
24 | 最大長度
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/Avalonia.XmlTranslator.Demo/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Avalonia.ReactiveUI;
3 |
4 | namespace Avalonia.XmlTranslator.Demo
5 | {
6 | internal class Program
7 | {
8 | // Initialization code. Don't use any Avalonia, third-party APIs or any
9 | // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
10 | // yet and stuff might break.
11 | [STAThread]
12 | public static void Main(string[] args) => BuildAvaloniaApp()
13 | .StartWithClassicDesktopLifetime(args);
14 |
15 | // Avalonia configuration, don't remove; also used by visual designer.
16 | public static AppBuilder BuildAvaloniaApp()
17 | => AppBuilder.Configure()
18 | .UsePlatformDetect()
19 | .UseReactiveUI()
20 | .LogToTrace();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Avalonia.XmlTranslator.Demo/Roots.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/Avalonia.XmlTranslator.Demo/ViewModels/MainWindowViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Globalization;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using AvaloniaXmlTranslator;
8 | using AvaloniaXmlTranslator.Models;
9 | using ReactiveUI;
10 |
11 | namespace Avalonia.XmlTranslator.Demo.ViewModels;
12 |
13 | public class MainWindowViewModel : ViewModelBase
14 | {
15 | public MainWindowViewModel()
16 | {
17 | Languages = I18nManager.Instance.Resources.Select(kvp => kvp.Value).ToList();
18 | SelectLanguage = Languages.FirstOrDefault(l => l.CultureName == I18nManager.Instance.Culture.Name);
19 |
20 | AllCultures = new ObservableCollection(I18nManager.Instance.GetAvailableCultures());
21 |
22 | var titleCurrentCulture = I18nManager.Instance.GetResource(Localization.Main.MainView.Title);
23 | var titleZhCN = I18nManager.Instance.GetResource(Localization.Main.MainView.Title, "zh-CN");
24 | var titleEnUS = I18nManager.Instance.GetResource(Localization.Main.MainView.Title, "en-US");
25 |
26 | Task.Run(async () =>
27 | {
28 | while (true)
29 | {
30 | CurrentTime = DateTime.Now;
31 | await Task.Delay(TimeSpan.FromSeconds(1));
32 | }
33 | });
34 | }
35 |
36 | public List Languages { get; set; }
37 | public LocalizationLanguage? _selectLanguage;
38 |
39 | public LocalizationLanguage? SelectLanguage
40 | {
41 | get => _selectLanguage;
42 | set
43 | {
44 | this.RaiseAndSetIfChanged(ref _selectLanguage, value);
45 | I18nManager.Instance.Culture = new CultureInfo(value.CultureName);
46 | }
47 | }
48 |
49 | private DateTime _currentTime;
50 |
51 | public DateTime CurrentTime
52 | {
53 | get => _currentTime;
54 | set => this.RaiseAndSetIfChanged(ref _currentTime, value);
55 | }
56 |
57 | public ObservableCollection AllCultures { get; }
58 | }
59 |
--------------------------------------------------------------------------------
/src/Avalonia.XmlTranslator.Demo/ViewModels/ViewModelBase.cs:
--------------------------------------------------------------------------------
1 | using ReactiveUI;
2 |
3 | namespace Avalonia.XmlTranslator.Demo.ViewModels;
4 |
5 | public class ViewModelBase : ReactiveObject
6 | {
7 | }
8 |
--------------------------------------------------------------------------------
/src/Avalonia.XmlTranslator.Demo/Views/MainWindow.axaml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
25 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
43 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
61 |
63 |
65 |
67 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/src/Avalonia.XmlTranslator.Demo/Views/MainWindow.axaml.cs:
--------------------------------------------------------------------------------
1 | using Avalonia.Controls;
2 |
3 | namespace Avalonia.XmlTranslator.Demo.Views;
4 |
5 | public partial class MainWindow : Window
6 | {
7 | public MainWindow()
8 | {
9 | InitializeComponent();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Avalonia.XmlTranslator.Demo/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/App.axaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/App.axaml.cs:
--------------------------------------------------------------------------------
1 | using System.Globalization;
2 | using Avalonia;
3 | using Avalonia.Controls.ApplicationLifetimes;
4 | using Avalonia.Markup.Xaml;
5 | using AvaloniaExtensions.Axaml.Demo.ViewModels;
6 | using AvaloniaExtensions.Axaml.Demo.Views;
7 | using AvaloniaExtensions.Axaml.Markup;
8 |
9 | namespace AvaloniaExtensions.Axaml.Demo
10 | {
11 | public partial class App : Application
12 | {
13 | public override void Initialize()
14 | {
15 | AvaloniaXamlLoader.Load(this);
16 | I18nManager.Instance.Culture = new CultureInfo("zh-CN");
17 | }
18 |
19 | public override void OnFrameworkInitializationCompleted()
20 | {
21 | if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
22 | {
23 | desktop.MainWindow = new MainWindow { DataContext = new MainWindowViewModel(), };
24 | }
25 |
26 | base.OnFrameworkInitializationCompleted();
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/Assets/cloud.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotnet9/AvaloniaExtensions/77d4e75175693536fae5abc0664524b53d6648ac/src/AvaloniaExtensions.Axaml.Demo/Assets/cloud.png
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/Assets/logo.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotnet9/AvaloniaExtensions/77d4e75175693536fae5abc0664524b53d6648ac/src/AvaloniaExtensions.Axaml.Demo/Assets/logo.ico
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/Assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotnet9/AvaloniaExtensions/77d4e75175693536fae5abc0664524b53d6648ac/src/AvaloniaExtensions.Axaml.Demo/Assets/logo.png
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/AvaloniaExtensions.Axaml.Demo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | WinExe
4 | net9.0;net9.0-windows;net10.0;net10.0-windows
5 | enable
6 | true
7 | true
8 | app.manifest
9 | true
10 |
11 |
12 | true
13 | true
14 |
15 |
16 | true
17 | true
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | True
45 | True
46 | Language.tt
47 |
48 |
49 | True
50 | True
51 | Resources.resx
52 |
53 |
54 |
55 |
56 |
57 | PublicResXFileCodeGenerator
58 | Resources.Designer.cs
59 |
60 |
61 |
62 |
63 |
64 | TextTemplatingFileGenerator
65 | Language.cs
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/I18n/Language.cs:
--------------------------------------------------------------------------------
1 |
2 | //------------------------------------------------------------------------------
3 | //
4 | // This code was generated by a tool.
5 | // Changes to this file may cause incorrect behavior and will be lost if
6 | // the code is regenerated.
7 | //
8 | //------------------------------------------------------------------------------
9 |
10 | namespace AvaloniaExtensions.Axaml.Demo.I18n;
11 |
12 | public static class Language
13 | {
14 | public static readonly string AppName = "AppName";
15 | public static readonly string Welcome = "Welcome";
16 | public static readonly string Running = "Running";
17 | public static readonly string NotRunning = "NotRunning";
18 | public static readonly string RunningCountInfo = "RunningCountInfo";
19 | public static readonly string CurrentTimeFormat = "CurrentTimeFormat";
20 | }
21 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/I18n/Language.tt:
--------------------------------------------------------------------------------
1 |
2 | <#@ template debug="false" hostspecific="true" language="C#" #>
3 | <#@ assembly name="System.Core" #>
4 | <#@ assembly name="System.Xml" #>
5 | <#@ assembly name="System.Xml.Linq" #>
6 | <#@ import namespace="System.Linq" #>
7 | <#@ import namespace="System.Text" #>
8 | <#@ import namespace="System.Collections.Generic" #>
9 | <#@ import namespace="System.Xml.Linq" #>
10 | <#@ import namespace="System.IO" #>
11 | <#@ output extension=".cs" #>
12 | //------------------------------------------------------------------------------
13 | //
14 | // This code was generated by a tool.
15 | // Changes to this file may cause incorrect behavior and will be lost if
16 | // the code is regenerated.
17 | //
18 | //------------------------------------------------------------------------------
19 | <#
20 | const string ResourceFileName = "Resources.resx";
21 | #>
22 |
23 | namespace <#=System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("NamespaceHint").ToString()#>;
24 |
25 | public static class Language
26 | {
27 | <#
28 | var resourceKeys = XElement.Load(this.Host.ResolvePath(ResourceFileName))
29 | .Elements("data")
30 | .Select(item => item.Attribute("name")?.Value)
31 | .Where(item => item != null);
32 |
33 | var resourceDesignerName = Path.GetFileNameWithoutExtension(ResourceFileName);
34 |
35 | foreach (string resourceKey in resourceKeys)
36 | {
37 | #>
38 | public static readonly string <#= resourceKey #> = "<#= resourceKey #>";
39 | <#
40 | }
41 | #>
42 | }
43 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/I18n/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace AvaloniaExtensions.Axaml.Demo.I18n {
12 | using System;
13 |
14 |
15 | ///
16 | /// 一个强类型的资源类,用于查找本地化的字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | public class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// 返回此类使用的缓存的 ResourceManager 实例。
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | public static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AvaloniaExtensions.Axaml.Demo.I18n.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// 重写当前线程的 CurrentUICulture 属性,对
51 | /// 使用此强类型资源类的所有资源查找执行重写。
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | public static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// 查找类似 AvaloniaExtensions.Axaml.Demo 的本地化字符串。
65 | ///
66 | public static string AppName {
67 | get {
68 | return ResourceManager.GetString("AppName", resourceCulture);
69 | }
70 | }
71 |
72 | ///
73 | /// 查找类似 The current time is {0} 的本地化字符串。
74 | ///
75 | public static string CurrentTimeFormat {
76 | get {
77 | return ResourceManager.GetString("CurrentTimeFormat", resourceCulture);
78 | }
79 | }
80 |
81 | ///
82 | /// 查找类似 Not running 的本地化字符串。
83 | ///
84 | public static string NotRunning {
85 | get {
86 | return ResourceManager.GetString("NotRunning", resourceCulture);
87 | }
88 | }
89 |
90 | ///
91 | /// 查找类似 Running 的本地化字符串。
92 | ///
93 | public static string Running {
94 | get {
95 | return ResourceManager.GetString("Running", resourceCulture);
96 | }
97 | }
98 |
99 | ///
100 | /// 查找类似 Running {0} operating system, {1} 的本地化字符串。
101 | ///
102 | public static string RunningCountInfo {
103 | get {
104 | return ResourceManager.GetString("RunningCountInfo", resourceCulture);
105 | }
106 | }
107 |
108 | ///
109 | /// 查找类似 Welcome to use I18n 的本地化字符串。
110 | ///
111 | public static string Welcome {
112 | get {
113 | return ResourceManager.GetString("Welcome", resourceCulture);
114 | }
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/I18n/Resources.ja-JP.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | AvaloniaExtensions.Axaml.Demo
122 |
123 |
124 | I 18 nへようこそ
125 |
126 |
127 | 実行中
128 |
129 |
130 | 未実行
131 |
132 |
133 | 実行中 {0} オペレーティングシステム,{1}
134 |
135 |
136 | 現在の時間は {0} です。
137 |
138 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/I18n/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | AvaloniaExtensions.Axaml.Demo
122 | Application Name
123 |
124 |
125 | Welcome to use I18n
126 |
127 |
128 | Running
129 |
130 |
131 | Not running
132 |
133 |
134 | Running {0} operating system, {1}
135 |
136 |
137 | The current time is {0}
138 |
139 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/I18n/Resources.zh-CN.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | AvaloniaExtensions.Axaml.Demo
122 |
123 |
124 | 欢迎使用I18n
125 |
126 |
127 | 正在运行
128 |
129 |
130 | 未运行
131 |
132 |
133 | 正在运行 {0} 操作系统,{1}
134 |
135 |
136 | 当前时间是 {0}
137 |
138 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/I18n/Resources.zh-Hant.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | AvaloniaExtensions.Axaml.Demo
122 |
123 |
124 | 歡迎使用I18n
125 |
126 |
127 | 正在運行
128 |
129 |
130 | 未運行
131 |
132 |
133 | 正在運行 {0} 作業系統,{1}
134 |
135 |
136 | 當前時間是 {0}
137 |
138 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/Models/AlarmStatus.cs:
--------------------------------------------------------------------------------
1 | namespace AvaloniaExtensions.Axaml.Demo.Models;
2 |
3 | public enum AlarmStatus
4 | {
5 | Normal,
6 | Overtime,
7 | OverLimit,
8 | UserChanged
9 | }
10 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/Models/RunStatusKind.cs:
--------------------------------------------------------------------------------
1 | namespace AvaloniaExtensions.Axaml.Demo.Models;
2 |
3 | public enum RunStatusKind
4 | {
5 | Running,
6 | NotRunning
7 | }
8 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Avalonia;
3 | using Avalonia.ReactiveUI;
4 |
5 | namespace AvaloniaExtensions.Axaml.Demo
6 | {
7 | internal sealed class Program
8 | {
9 | // Initialization code. Don't use any Avalonia, third-party APIs or any
10 | // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
11 | // yet and stuff might break.
12 | [STAThread]
13 | public static void Main(string[] args) => BuildAvaloniaApp()
14 | .StartWithClassicDesktopLifetime(args);
15 |
16 | // Avalonia configuration, don't remove; also used by visual designer.
17 | public static AppBuilder BuildAvaloniaApp()
18 | => AppBuilder.Configure()
19 | .UsePlatformDetect()
20 | .WithInterFont()
21 | .LogToTrace()
22 | .UseReactiveUI();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/Styles/Brushes.axaml:
--------------------------------------------------------------------------------
1 |
3 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/ViewLocator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Avalonia.Controls;
3 | using Avalonia.Controls.Templates;
4 | using AvaloniaExtensions.Axaml.Demo.ViewModels;
5 |
6 | namespace AvaloniaExtensions.Axaml.Demo
7 | {
8 | public class ViewLocator : IDataTemplate
9 | {
10 | public Control? Build(object? data)
11 | {
12 | if (data is null)
13 | return null;
14 |
15 | var name = data.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
16 | var type = Type.GetType(name);
17 |
18 | if (type != null)
19 | {
20 | var control = (Control)Activator.CreateInstance(type)!;
21 | control.DataContext = data;
22 | return control;
23 | }
24 |
25 | return new TextBlock { Text = "Not Found: " + name };
26 | }
27 |
28 | public bool Match(object? data)
29 | {
30 | return data is ViewModelBase;
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/ViewModels/MainWindowViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Threading.Tasks;
5 | using AvaloniaExtensions.Axaml.Demo.Models;
6 | using AvaloniaExtensions.Axaml.Markup;
7 | using ReactiveUI;
8 |
9 | namespace AvaloniaExtensions.Axaml.Demo.ViewModels;
10 |
11 | public class MainWindowViewModel : ViewModelBase
12 | {
13 | public MainWindowViewModel()
14 | {
15 | Task.Run(async () =>
16 | {
17 | while (true)
18 | {
19 | CurrentTime = DateTime.Now;
20 | await Task.Delay(TimeSpan.FromSeconds(1));
21 | }
22 | });
23 | }
24 |
25 | public string Title => "AppName";
26 |
27 | private bool _status;
28 |
29 | public bool Status
30 | {
31 | get => _status;
32 | set => this.RaiseAndSetIfChanged(ref _status, value);
33 | }
34 |
35 | private DateTime _currentTime;
36 |
37 | public DateTime CurrentTime
38 | {
39 | get => _currentTime;
40 | set => this.RaiseAndSetIfChanged(ref _currentTime, value);
41 | }
42 |
43 | private AlarmStatus _alarmStatus;
44 |
45 | public AlarmStatus AlarmStatus
46 | {
47 | get => _alarmStatus;
48 | set => this.RaiseAndSetIfChanged(ref _alarmStatus, value);
49 | }
50 |
51 | private RunStatusKind _statusKind;
52 |
53 | public RunStatusKind StatusKind
54 | {
55 | get => _statusKind;
56 | set => this.RaiseAndSetIfChanged(ref _statusKind, value);
57 | }
58 |
59 | public void RaiseChangeLanguageHandler(string language)
60 | {
61 | I18nManager.Instance.Culture = new CultureInfo(language);
62 | }
63 |
64 | public List? ItemsA { get; }
65 | public List? ItemsB { get; } = new List() { "First", "Second" };
66 |
67 | public void RaiseChangeStatusCommandHandler()
68 | {
69 | Status = !Status;
70 | StatusKind = Status ? RunStatusKind.Running : RunStatusKind.NotRunning;
71 | AlarmStatus = (AlarmStatus)Enum.Parse(typeof(AlarmStatus),
72 | Random.Shared.Next(Enum.GetNames(typeof(AlarmStatus)).Length).ToString());
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/ViewModels/ViewModelBase.cs:
--------------------------------------------------------------------------------
1 | using ReactiveUI;
2 |
3 | namespace AvaloniaExtensions.Axaml.Demo.ViewModels
4 | {
5 | public class ViewModelBase : ReactiveObject
6 | {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/Views/MainWindow.axaml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
72 |
76 |
80 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
114 |
117 |
120 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/Views/MainWindow.axaml.cs:
--------------------------------------------------------------------------------
1 | using Avalonia.Controls;
2 | using Avalonia.Markup.Xaml;
3 |
4 | namespace AvaloniaExtensions.Axaml.Demo.Views
5 | {
6 | public partial class MainWindow : Window
7 | {
8 | public MainWindow()
9 | {
10 | InitializeComponent();
11 | }
12 |
13 | private void InitializeComponent()
14 | {
15 | AvaloniaXamlLoader.Load(this);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml.Demo/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using Avalonia.Metadata;
2 |
3 | [assembly: XmlnsDefinition("https://codewf.com", "AvaloniaExtensions.Axaml.Markup")]
4 | [assembly: XmlnsDefinition("https://codewf.com", "AvaloniaExtensions.Axaml.Converters")]
5 | [assembly: XmlnsPrefix("AvaloniaExtensions.Axaml.Markup", "i18n")]
6 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml/AvaloniaExtensions.Axaml.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | AvaloniaExtensions.Axaml
5 | netstandard2.0
6 | enable
7 | latest
8 | Library
9 | true
10 | 1.0.4.0
11 | 沙漠尽头的狼
12 | 为Avalonia UI开发带来便利的语法糖库。A syntactic sugar library that brings convenience to Avalonia UI development.
13 | https://github.com/dotnet9/AvaloniaExtensions
14 | MIT
15 | logo.png
16 | https://github.com/dotnet9/AvaloniaExtensions
17 | C#; AvaloniaUI;
18 | false
19 | git
20 | MIT
21 | https://dotnet9.com
22 | README.md
23 | true
24 |
25 |
26 |
27 |
28 | true
29 |
30 |
31 |
32 | true
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml/Converters/EnumToBooleanConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using Avalonia.Data;
4 | using Avalonia.Data.Converters;
5 |
6 | namespace AvaloniaExtensions.Axaml.Converters;
7 |
8 | public class EnumToBooleanConverter : IValueConverter
9 | {
10 | public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
11 | value?.Equals(parameter);
12 |
13 | public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) =>
14 | value?.Equals(true) == true ? parameter : BindingOperations.DoNothing;
15 | }
16 |
--------------------------------------------------------------------------------
/src/AvaloniaExtensions.Axaml/Converters/I18n/I18nConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Linq;
5 | using Avalonia.Data.Converters;
6 | using AvaloniaExtensions.Axaml.Markup;
7 |
8 | // ReSharper disable once CheckNamespace
9 | namespace AvaloniaExtensions.Axaml.Converters;
10 |
11 | public class I18nConverter(I18nBinding owner) : IMultiValueConverter
12 | {
13 | public object? Convert(IList