我如何根据本地化呈现不同的 webview?
How can i present different webview based on localization?
我有一个应用程序,我想将其本地化为多种语言。条款和条件页面是网址,对于我支持的每种语言,它都有不同的 link.
在我显示该 Web 视图的控制器中,我如何 "localize" 这个 link,即基于区域设置的开关 link?
正如 Teja Nandamuri 评论的那样,您可以简单地在 Localizable.strings
文件中定义链接。
例如,如果您支持两种语言,比方说英语和法语,您将拥有类似的内容:
在您的 Localizable.strings (English)
文件中:
"my_terms_url" = "https://mywebsite.com/my_terms/en";
在您的 Localizable.strings (French)
文件中:
"my_terms_url" = "https://mywebsite.com/my_terms/fr";
要建立 Randy 的答案,您需要使用以下代码来获取站点:
Objective-C:
// Getting the URL for the language
NSString *websiteString = NSLocalizedString(@"website", nil);
// Calling said URL
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: websiteString]]];
Swift:
// Getting the URL for the language
let websiteString = NSLocalizedString("website", comment: "language");
// Calling said URL
UIWebView.loadRequest(webviewInstance)(NSURLRequest(URL: NSURL(string: websiteString)!))
并且在您的 Localizable.strings
语言文件中:
// "language" would differ for the various supported languages
"website" = "https://destination.com/language";
我有一个应用程序,我想将其本地化为多种语言。条款和条件页面是网址,对于我支持的每种语言,它都有不同的 link.
在我显示该 Web 视图的控制器中,我如何 "localize" 这个 link,即基于区域设置的开关 link?
正如 Teja Nandamuri 评论的那样,您可以简单地在 Localizable.strings
文件中定义链接。
例如,如果您支持两种语言,比方说英语和法语,您将拥有类似的内容:
在您的 Localizable.strings (English)
文件中:
"my_terms_url" = "https://mywebsite.com/my_terms/en";
在您的 Localizable.strings (French)
文件中:
"my_terms_url" = "https://mywebsite.com/my_terms/fr";
要建立 Randy 的答案,您需要使用以下代码来获取站点:
Objective-C:
// Getting the URL for the language
NSString *websiteString = NSLocalizedString(@"website", nil);
// Calling said URL
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: websiteString]]];
Swift:
// Getting the URL for the language
let websiteString = NSLocalizedString("website", comment: "language");
// Calling said URL
UIWebView.loadRequest(webviewInstance)(NSURLRequest(URL: NSURL(string: websiteString)!))
并且在您的 Localizable.strings
语言文件中:
// "language" would differ for the various supported languages
"website" = "https://destination.com/language";