Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何读取Localizable.strings的内容并将其放入UIWebView_Javascript_Objective C_Ios_Uiwebview_Localizable.strings - Fatal编程技术网

Javascript 如何读取Localizable.strings的内容并将其放入UIWebView

Javascript 如何读取Localizable.strings的内容并将其放入UIWebView,javascript,objective-c,ios,uiwebview,localizable.strings,Javascript,Objective C,Ios,Uiwebview,Localizable.strings,在我的应用程序中,我有一个文本文件,其中包含以下内容: <html> <style rel="stylesheet" type="text/css"> body { font-family: Arial, sans-serif; font-size: 18px; color: #333333; padding: 14px; tex

在我的应用程序中,我有一个文本文件,其中包含以下内容:

<html>
    <style rel="stylesheet" type="text/css">
        body {
            font-family: Arial, sans-serif;
            font-size: 18px;
            color: #333333;
            padding: 14px;
            text-align: justify;
        }
        h2 {
            font-size: 18px;
        }
    </style>
    <body>
        <p>
        This is the first statement.
        <br>
        This is the second statement.
        </p>
    </body>
</html>
FIRST_STATEMENT = "This is the first statement";
SECOND_STATEMENT = "This is the second statement";
// message body
NSString *htmlString = [NSString stringWithFormat:
            @"<body>"
            "<p>"
            "%@" // first statement.
            "<br />"
            "%@" // second statement
            "<br />"
            "%d" // some integer value
            "</p>"
            "</body>",
            NSLocalizedString(@"This is the first statement.", nil),
            NSLocalizedString(@"This is the second statement.", nil),
            intSomeValue];

现在的问题是,如何从Localizable.strings访问数据,以便将它们放到UIWebView对象的内容中?我正在考虑javascript,但我不知道如何实现它。有什么想法吗?

可以尝试制作html文件模板并将

%@

在您希望本地化字符串的位置/标记处,然后将模板文件放入App Bundle/Documents目录中并使用-

NSString*anHtmlStr=[[NSBundle mainBundle]路径用于资源:@“templateFile” 类型:@“html”]//如果文件在应用程序包中,请使用

//NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,是)

anHtmlStr=[NSString STRINGWITHCONTENTS文件:anHtmlStr编码:NSUTF8STRING编码错误:&err]

anHtmlStr=[NSString stringWithFormat:anHtmlStr,NSLocalizedString(@“key”,@“comment”)

[webView loadHTMLString:anHtmlStr baseURL:baseURL]


根据UIWebView判断,我假设您正在使用xcode和objective-c。您可以这样做:

<html>
    <style rel="stylesheet" type="text/css">
        body {
            font-family: Arial, sans-serif;
            font-size: 18px;
            color: #333333;
            padding: 14px;
            text-align: justify;
        }
        h2 {
            font-size: 18px;
        }
    </style>
    <body>
        <p>
        This is the first statement.
        <br>
        This is the second statement.
        </p>
    </body>
</html>
FIRST_STATEMENT = "This is the first statement";
SECOND_STATEMENT = "This is the second statement";
// message body
NSString *htmlString = [NSString stringWithFormat:
            @"<body>"
            "<p>"
            "%@" // first statement.
            "<br />"
            "%@" // second statement
            "<br />"
            "%d" // some integer value
            "</p>"
            "</body>",
            NSLocalizedString(@"This is the first statement.", nil),
            NSLocalizedString(@"This is the second statement.", nil),
            intSomeValue];
//消息正文
NSString*htmlString=[NSString stringWithFormat:
@""
“”
“%@”//first语句。
“
” “%@”//second语句 “
” “%d”//某个整数值 “

” "", NSLocalizedString(@“这是第一个语句”,无), NSLocalizedString(@“这是第二个语句。”,无), intSomeValue];
可以将字符串拆分为多行。顺便说一句,如果你有很多文本,那么你真的需要注释行来跟踪哪个%@表示什么字符串替换值