From ff946f6a7d240d4c6881a75a3b73ac9d1eefbb71 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Wed, 15 Mar 2017 14:55:50 +1100 Subject: [PATCH] Translate category names. --- .../fdroid/views/categories/CategoryController.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/fdroid/fdroid/views/categories/CategoryController.java b/app/src/main/java/org/fdroid/fdroid/views/categories/CategoryController.java index 822236a23..d18dc6bb1 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/categories/CategoryController.java +++ b/app/src/main/java/org/fdroid/fdroid/views/categories/CategoryController.java @@ -58,7 +58,7 @@ public class CategoryController extends RecyclerView.ViewHolder implements Loade void bindModel(@NonNull String categoryName) { currentCategory = categoryName; - heading.setText(categoryName); + heading.setText(translateCategory(categoryName)); viewAll.setVisibility(View.INVISIBLE); loaderManager.initLoader(currentCategory.hashCode(), null, this); loaderManager.initLoader(currentCategory.hashCode() + 1, null, this); @@ -66,6 +66,16 @@ public class CategoryController extends RecyclerView.ViewHolder implements Loade background.setBackgroundColor(getBackgroundColour(categoryName)); } + /** + * Attempt to translate category name with fallback to default name if no translation available + */ + private String translateCategory(@NonNull String categoryName) { + String resId = categoryName.replace(" & ", "_").replace(" ", "_").replace("'", ""); + int id = activity.getResources().getIdentifier("category_" + resId, "string", activity.getPackageName()); + return id == 0 ? categoryName : activity.getString(id); + + } + public static int getBackgroundColour(@NonNull String categoryName) { // Seed based on the categoryName, so that each time we try to choose a colour for the same // category it will look the same for each different user, and each different session. @@ -130,6 +140,7 @@ public class CategoryController extends RecyclerView.ViewHolder implements Loade appCardsAdapter.setAppCursor(null); } + @SuppressWarnings("FieldCanBeLocal") private final View.OnClickListener onViewAll = new View.OnClickListener() { @Override public void onClick(View v) {