Skip to content

Commit

Permalink
Merge pull request #3907 from osmandapp/help_labels_fix
Browse files Browse the repository at this point in the history
Use label from json if string is not available
  • Loading branch information
alex-osm authored Aug 9, 2024
2 parents 8596e0d + a6fc44b commit 121952f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Sources/Controllers/Help/HelpDetailsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ final class HelpDetailsViewController: OABaseNavbarViewController {
continue
}

let title = MenuHelpDataService.shared.getArticleName(from: article.url)
let title = MenuHelpDataService.shared.getArticleName(from: article)
let url = article.url
let articleRow = childArticlesSection.createNewRow()
articleRow.cellType = OASimpleTableViewCell.getIdentifier()
Expand Down
15 changes: 10 additions & 5 deletions Sources/Controllers/Help/MenuHelpDataService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@

import UIKit

@objc protocol ArticleRepresentable {
var title: String { get }
var url: String { get }
}

@objcMembers
final class PopularArticle: NSObject {
final class PopularArticle: NSObject, ArticleRepresentable {
let title: String
let url: String

Expand All @@ -31,7 +36,7 @@ final class TelegramChat: NSObject {
}

@objcMembers
final class ArticleNode: NSObject {
final class ArticleNode: NSObject, ArticleRepresentable {
var title: String
var url: String
var level: Int
Expand Down Expand Up @@ -175,14 +180,14 @@ final class MenuHelpDataService: NSObject, XMLParserDelegate {
}
}

func getArticleName(from url: String) -> String {
let articleId = getArticlePropertyName(from: url)
func getArticleName(from article: ArticleRepresentable) -> String {
let articleId = getArticlePropertyName(from: article.url)
if let specialName = getSpecialArticleName(for: articleId) {
return specialName
} else {
let articleNameKey = "help_article_\(articleId)_name"
let localized = localizedString(articleNameKey)
return localized.isEmpty ? articleId.replacingOccurrences(of: "_", with: " ").capitalized : localized
return localized == articleNameKey ? article.title : localized
}
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Controllers/Help/OAHelpViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ - (void)generateData

for (PopularArticle *article in _mostViewedArticles)
{
NSString *title = [_helpDataManager getArticleNameFrom:article.url];
NSString *title = [_helpDataManager getArticleNameFrom:article];
NSString *url = article.url;
OATableRowData *articleRow = [popularArticlesSection createNewRow];
[articleRow setCellType:[OASimpleTableViewCell getCellIdentifier]];
Expand All @@ -109,7 +109,7 @@ - (void)generateData

for (ArticleNode *articleNode in _parsedArticles)
{
NSString *title = [_helpDataManager getArticleNameFrom:articleNode.url];
NSString *title = [_helpDataManager getArticleNameFrom:articleNode];
if ([title isEqualToString:OALocalizedString(@"troubleshooting")])
{
_troubleshootingChildArticles = articleNode.childArticles;
Expand Down Expand Up @@ -138,7 +138,7 @@ - (void)generateData
if ([childArticle.url isEqualToString:@"https://osmand.net/docs/user/troubleshooting/android_auto"])
continue;

NSString *title = [_helpDataManager getArticleNameFrom:childArticle.url];
NSString *title = [_helpDataManager getArticleNameFrom:childArticle];
OATableRowData *row = [troubleshootingSection createNewRow];
[row setCellType:[OASimpleTableViewCell getCellIdentifier]];
[row setKey:@"troubleshooting"];
Expand Down

0 comments on commit 121952f

Please sign in to comment.