启用位置后,如何重新加载UI中的文本

发布于 2025-02-11 22:24:38 字数 305 浏览 2 评论 0原文

我有一个基于位置本地化的应用程序。如果已经启用了设备位置,它可以完美地工作。但是,如果不是这样,我们在打开放映时要求征求位置许可。 TF用户点击是的,然后我想更改应用程序语言。在这种情况下,当前页面语言没有变化,语言更改将在其余页面中反映。

<Label Text={"lan:Translate Notification"}>

我正在绑定这样的静态文本。我已经提到了此博客:https://mindofai.github.io/implementing-localization-with-xamarin.forms/

I have an app with localization based on the location. It works perfectly if the device location is already enabled. But if it is not, we ask for location permission while opening the aplication. Tf the user clicks yes then I want to change the app language. In this case the current page language is not changing, and the language change will reflect in the remaining pages.

<Label Text={"lan:Translate Notification"}>

I am binding the static text like this. I have referred this blog: https://mindofai.github.io/Implementing-Localization-with-Xamarin.Forms/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抹茶夏天i‖ 2025-02-18 22:24:38

您可以处理 xamarin forms in xamarin forms strong>批准文件,这些步骤是:

创建一个批准文件

每种您要支持的每种语言添加一个RESX文件。 “它必须遵循特定的命名约定:使用与基本资源文件(例如批准)的文件名相同,然后使用一个(。)然后是语言代码”。

在批准文件中添加文本:代码,例如:

<data name="NotesLabel" xml:space="preserve">
    <value>Notas:</value>
    <comment>label for input field</comment>
  </data>
  <data name="NotesPlaceholder" xml:space="preserve">
    <value>por ejemplo . comprar leche</value>
    <comment>example input for notes field</comment>
  </data>

在代码中使用批准文件

要使用批准文本,您必须在XAML中导入批准的类名称空间并加载并加载它通过使用静态参考。

这是一篇有关在xamarin.forms中掌握多语言 谈论您在添加多语言支持时可能会遇到的一些典型问题。

You can handle Multilingual in Xamarin forms with AppResource File,the steps are :

Create an AppResource File:

Add one resx file per each language you want to support. “It must follow a specific naming convention: use the same filename as the base resources file (eg. AppResources) followed by a period (.) and then the language code”.

Add your texts in your AppResources file: code like:

<data name="NotesLabel" xml:space="preserve">
    <value>Notas:</value>
    <comment>label for input field</comment>
  </data>
  <data name="NotesPlaceholder" xml:space="preserve">
    <value>por ejemplo . comprar leche</value>
    <comment>example input for notes field</comment>
  </data>

Use your AppResources file in your code:

To use your AppResource texts you have to import the AppResources class namespace in XAML and load it by using static reference.

Here is a article about Mastering Multilingual in Xamarin.Forms which talk about some typical problems that you might face when adding multilingual support .

晚雾 2025-02-18 22:24:38

当您启用位置服务时,您可以拥有当前的文化信息:

  1. 删除导航堆栈中的每个页面并再次加载当前页面。
  2. 重新启动应用程序

,如果您的应用程序以前运行,则可以在本地存储本地文化信息(即偏好存储),并在设置导航堆栈之前将先前已知的文化加载在App.cs上。

At the time you have the location service enabled and you've got the current culture info you can:

  1. Remove every page inside the navigation stack and load current page again.
  2. Restart the application

If your application had run before, you could store the culture info locally (i.e Preference storage) and load the previously known culture at the App.cs before setting the Navigation stack.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文