Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] - Fix an issue with reader-mode page language not specified #27676

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ios/brave-ios/Sources/Brave/Frontend/Reader/Reader.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at https://mozilla.org/MPL/2.0/. -->
<html>
<html lang="%READER-PAGE-LANGUAGE%">

<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ struct ReaderModeUtils {
.replacingOccurrences(of: "%READER-STYLE%", with: initialStyle.encode())
.replacingOccurrences(of: "%READER-DOMAIN%", with: simplifyDomain(readabilityResult.domain))
.replacingOccurrences(of: "%READER-URL%", with: readabilityResult.url)
.replacingOccurrences(
of: "%READER-PAGE-LANGUAGE%",
with: readabilityResult.documentLanguage.javaScriptEscapedString?.unquotedIfNecessary
?? ""
)
.replacingOccurrences(
of: "%READER-TITLE%",
with: readabilityResult.title.javaScriptEscapedString?.unquotedIfNecessary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ function checkReadability() {
readabilityResult.cspMetaTags = [...cspMetaTags].map((e) => new XMLSerializer().serializeToString(e));
}

let documentLanguage = document.documentElement.lang || document.querySelector('meta[http-equiv="Content-Language"]')?.content || null;
if (documentLanguage) {
readabilityResult.documentLanguage = documentLanguage;
}

debug({Type: "ReaderModeStateChange", Value: readabilityResult !== null ? "Available" : "Unavailable"});
webkit.messageHandlers.readerModeMessageHandler.postMessage({"securityToken": SECURITY_TOKEN, "data": {Type: "ReaderModeStateChange", Value: readabilityResult !== null ? "Available" : "Unavailable"}});
webkit.messageHandlers.readerModeMessageHandler.postMessage({"securityToken": SECURITY_TOKEN, "data": {Type: "ReaderContentParsed", Value: readabilityResult}});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ struct ReadabilityResult {
var domain = ""
var url = ""
var content = ""
var documentLanguage = ""
var title = ""
var credits = ""
var direction = "auto"
Expand All @@ -191,6 +192,9 @@ struct ReadabilityResult {
if let content = dict["content"] as? String {
self.content = content
}
if let documentLanguage = dict["documentLanguage"] as? String {
self.documentLanguage = documentLanguage
}
if let title = dict["title"] as? String {
self.title = title
}
Expand All @@ -214,6 +218,7 @@ struct ReadabilityResult {
let domain = object["domain"].string
let url = object["url"].string
let content = object["content"].string
let documentLanguage = object["documentLanguage"].string
let title = object["title"].string
let credits = object["credits"].string
let direction = object["dir"].string
Expand All @@ -226,6 +231,7 @@ struct ReadabilityResult {
self.domain = domain!
self.url = url!
self.content = content!
self.documentLanguage = documentLanguage ?? ""
self.title = title!
self.credits = credits!
self.direction = direction ?? "auto"
Expand All @@ -235,7 +241,8 @@ struct ReadabilityResult {
/// Encode to a dictionary, which can then for example be json encoded
func encode() -> [String: Any] {
return [
"domain": domain, "url": url, "content": content, "title": title, "credits": credits,
"domain": domain, "url": url, "content": content, "documentLanguage": documentLanguage,
"title": title, "credits": credits,
"dir": direction, "cspMetaTags": cspMetaTags,
]
}
Expand Down
Loading