Skip to content

Commit

Permalink
tolgee use for localize
Browse files Browse the repository at this point in the history
  • Loading branch information
TenzDelek committed Feb 22, 2025
1 parent a9d6abc commit 6f1f4f7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 53 deletions.
40 changes: 10 additions & 30 deletions src/components/topics/Topics.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {getAlphabet, LANGUAGE} from "../../utils/Constants.js";
import {LANGUAGE} from "../../utils/Constants.js";
import axiosInstance from "../../config/axios-config.js";
import {useQuery} from "react-query";
import { useState, useEffect } from "react";
import { useState } from "react";
import {useNavigate, useParams} from "react-router-dom";
import {Button, Card, Col, Container, Form, Row} from "react-bootstrap";
import "./Topics.scss"
Expand All @@ -22,30 +22,10 @@ const Topics = () => {
const [parentId, setParentId] = useState(id || "");
const [searchTerm, setSearchTerm] = useState("");
const [selectedLetter, setSelectedLetter] = useState("");
const [currentLanguage, setCurrentLanguage] = useState(localStorage.getItem(LANGUAGE) || "bo-IN");
const [alphabetList, setAlphabetList] = useState(getAlphabet(currentLanguage));

useEffect(() => {
const handleStorageChange = () => {
const newLanguage = localStorage.getItem(LANGUAGE) || "bo-IN";
setCurrentLanguage(newLanguage);
setAlphabetList(getAlphabet(newLanguage));
};

window.addEventListener('storage', handleStorageChange);
const interval = setInterval(() => {
const storedLanguage = localStorage.getItem(LANGUAGE) || "bo-IN";
if (storedLanguage !== currentLanguage) {
setCurrentLanguage(storedLanguage);
setAlphabetList(getAlphabet(storedLanguage));
}
}, 1000);

return () => {
window.removeEventListener('storage', handleStorageChange);
clearInterval(interval);
};
}, [currentLanguage]);
const translatedKey = t("topic.alphabet");
const cleanAlphabetArray = translatedKey
.split("")
.filter((char) => char.match(/[a-zA-Z.\u0F00-\u0FFF]/));

const { data: topicsData, isLoading: topicsIsLoading } = useQuery(
["topics", parentId],
Expand Down Expand Up @@ -134,8 +114,8 @@ const Topics = () => {
</Card>
);
}

const renderTopicTitle = () => {
const renderTopicTitle = () => {
return <h4 className="topics-title listtitle">
{parentId && id ? t(`topic.${parentId}`) : t("topic.search_topics")}
</h4>
Expand All @@ -151,9 +131,9 @@ const Topics = () => {
/>

<div className="alphabet-filter">
{alphabetList.map((letter) => (
{cleanAlphabetArray.map((letter,index) => (
<Button
key={letter}
key={index}
variant={selectedLetter === letter ? "primary" : "outline-secondary"}
className="alphabet-button listsubtitle"
onClick={() => handleLetterClick(letter)}
Expand Down
11 changes: 10 additions & 1 deletion src/i18n/bo-IN.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@
"profile.at": "ལ་",
"profile.averages_pecha_user": "ཆ་སྙོམས་དཔེ་ཆ་དྲ་ཆིགས་སྤྱོད་མཁན།",
"profile.buddhish_text_tracker": "སྤྱི་བསྡོམས་རྩིས་ཁྲ།",
"profile.buddhist_tracker.favorite_sheets": "ཁྱེད་རང་དགའ་ཤོས་ཀྱི་ཤོག་ལེབ།",
"profile.buddhist_tracker.favorite_texts": "ཁྱེད་རང་དགའ་ཤོས་ཀྱི་ཡིག་ཆ།",
"profile.collection_description": "ཁྱེད་ཀྱིས་རང་གི་འདོད་པ་ལྟར་ཤོག་ལྷེ་དང་ཡང་ན་སྤྱི་སྤྱོད་ཤོག་ལྷེ་རྣམས་གོ་རིམ་བསྒྲིག་པར་ཚོགས་མཛོད་བེད་སྤྱོད་གཏོང་ཆོག་ཚོགས་མཛོད་རྣམས་སྒེར་གྱི་མཉམ་སྤྱོད་བྱེད་ཆོག་པའམ་ཡང་ན་སྤྱི་སྤྱོད་བྱེད་ཆོག་པ་ཡིན།",
"profile.edit_profile": "ངོ་སྤྲོད་རྩོམ་སྒྲིག",
"profile.etc": "ལ་སོགས་པ།",
Expand Down Expand Up @@ -460,7 +462,9 @@
"sheet.delete_sheet": "ཟིན་བྲིས་འདི་བསུབ།",
"sheet.delete_warning_msg": "ཁྱེད་ཀྱིས་ཤོག་ངོས་འདི་བསུབ་རྒྱུ་གཏན་འཁེལ་ཡིན་ནམ། འདི་བསུབ་རྗེས་སླར་གསོ་བྱེད་མི་ཐུབ།",
"sheet.edit": "རྩོམ་སྒྲིག",
"sheet.editor.write_something": "Write something...",
"sheet.editor.source.input_field.placeholder": "ཡི་གེ ཡང་ན བསམ་བཀོད་མཛོད་པའི་མིང་འཚོལ།",
"sheet.editor.untitled": "མིང་མེད",
"sheet.editor.write_something": "འདིར་རྩོམ་འབྲི...",
"sheet.edit_source_title": "རྒྱུ་ཆའི་མཚན་བྱང་རྩོམ་སྒྲིག",
"sheet.embed_sheet": "Embed Sheet",
"sheet.embed_sheet_description": "གཤམ་གྱི་ཨང་རྟགས་འདི་བཤུས་ཏེ། རང་འདོད་ལྟར་མཐོ་དམན་དང་ཞེང་ཚད་སྒྲིག་སྦྱོར་བྱ་ཆོག།",
Expand Down Expand Up @@ -555,6 +559,7 @@
"side_nav.about_pecha_description": "དཔེ་ཆ་དྲ་བའི་ནང་ཁྱེད་ཀྱིས་ཆོས་ཀྱི་ཚིགས་བཅད་རེ་ཀློག་ཚེ་དེའི་ཁུངས་དང་། འགྲེལ་བཤད། འགྱུར་མ། འབྲེལ་ཡོད་བསྟན་བཅོས། བྱིས་འགྲེལ། ཀློག་པོ་གཞན་གྱི་ཟིན་བྲིས་སོགས་ལ་དུས་གཅིག་ཏུ་ལྟ་ཐུབ།",
"side_nav.about_pecha_title": "ནང་པའི་དཔེ་ཆ་དྲ་བ།",
"side_nav.about_text": "ཡིག་ཆ་འདིའི་སྐོར།",
"side_nav.catetory.about_category": "{{category_name}} གྱི་སྐོར།",
"side_nav.collection.description": "འཛམ་གླིང་ས་ཆ་མི་འདྲ་བ་མང་པོ་ལ་ཡོད་པའི་ཚོགས་པ་དང་། མི་སྒེར་པ་རྣམས་ཀྱིས་ནང་དོན་གྱི་སྒོ་ནས་བསྒྲིགས་པའི་ཆེད་བསྒྲིགས་གནང་བ་དག། སོ་སོའི་འདོད་པ་དང་མཐུན་ནས་ལྟ་ཀློག་བྱེད་པར་བཞག་ཡོད།",
"side_nav.community.join_conversation": "བགྲོ་གླེང་ནང་ཞུགས།",
"side_nav.download_text": "ཡིག་ཆ་ཕབ་ལེན།",
Expand Down Expand Up @@ -654,6 +659,9 @@
"text.reader_option_menu.show_only_vowels": "དབྱངས་ཡིག་གི་རྟགས་ཁོ་ན་སྟོན།",
"text.reader_option_menu.show_puntuation": "ཚེག་ཤད་སྟོན།",
"text.reader_option_menu.show_vowels": "དབྱངས་ཡིག་དང་དབྱངས་རྟགས་སྟོན།",
"text.reader_option_menu.source": "ཁུངས།",
"text.reader_option_menu.source_with_translation": "ཁུངས་དང་འགྱུར་མ།",
"text.reader_option_menu.translation": "འགྱུར་མ།",
"text.reader_option_menu.vocalization": "ངག",
"text.reader_option_menu.vowels": "དབྱངས་ཡིག",
"text.reference": "དཔྱད་གཞི།",
Expand Down Expand Up @@ -725,6 +733,7 @@
"topic.admin.title_must_be_provided": "མཚན་བྱང་ངེས་པར་དུ་འབྲི་དགོས།",
"topic.admin.topic_editor": "བརྗོད་གཞི་རྩོམ་སྒྲིག་བྱེད་ཆས།",
"topic.all_topics": "བརྗོད་གཞི་ཆ་ཚང་།",
"topic.alphabet": "ཀཁགངཅཆཇཉཏཐདནཔཕབམཙཚཛཝཞཟའཡརལཤསཧཨ",
"topic.a_to_z": "ཀ ནས་ ཨ བར་གྱི་བརྗོད་གཞི་ཚང་མ།",
"topic.browse_topic": "བརྗོད་གཞིའི་ཐོ་གཞུང་ཆ་ཚང་ལ་མིག་བཤེར་དང་ཡང་ན་འཚོལ་ཞིབ་གྱིས།",
"topic.combine_source": "ཡིག་མཛོད་ནང་ལ་ཡོད་པའི་ལུང་ཚིག་གཞི་ལ་བཞག་ནས། ཁྱེད་རང་ཉིད་ཀྱི་བསམ་ཚུལ་དང་དྲི་བ། འདྲ་པར། བརྙན་ལ་སོགས་པ་བསྣན་ནས་མཉམ་སྡེབ་བྱེད་ཆོག།",
Expand Down
39 changes: 28 additions & 11 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@
"language.romanian": "Romanian",
"language.russian": "Russian",
"language.sami": "Sami",
"language.sanskrit": "Sanskrit",
"language.scots": "Scots",
"language.serbian": "Serbian",
"language.sinhala": "Sinhala",
Expand Down Expand Up @@ -338,25 +339,28 @@
"message.warning_delete_reading_history": "Turning this feature off will permanently delete your reading history.",
"message.we_only_understand_connection_betweeen_two_texts": "We currently only understand connections between two texts",
"modal.sign_up.default.love_learning": "Love Learning?",
"modal.sign_up.default.sign_up__to_get_more_from_sefaria": "Sign up to get more from Sefaria",
"modal.sign_up.default.sign_up__to_get_more_from_sefaria": "Sign up to get more from Pecha",
"modal.sign_up.love_learning": "Love Learning?",
"modal.sign_up.signup_to_get_more_from_pecha": "Sign up to get more from Sefaria",
"modal.sign_up.signup_to_get_more_from_pecha": "Sign up to get more from Pecha",
"modal.sign_up.stay_in_the_know": "Stay in the know",
"model.message_model.explore_other_text": "Explore other Texts",
"model.message_model.message": "Text is not available or you do not have permission to access it.",
"model.message_model.message_type": "Warning",
"model.sign_up.add_connection.connection_to_another_text": "Want to document a connection to another text?",
"model.sign_up.add_connection.content_list.add_interconnection_and_translation": "Add interconnections & translations",
"model.sign_up.add_connection.content_list.build_and_share_source_sheet": "Build & share source sheets",
"model.sign_up.add_connection.content_list.get_updates_on_new_texts": "Get updates on new texts",
"model.sign_up.add_connection.content_list.take_notes": "Take notes",
"model.sign_up.add_connection.create_free_account": "Create a free account to do more on Sefaria",
"model.sign_up.add_connection.create_free_account": "Create a free account to do more on Pecha",
"model.sign_up.add_to_sheet.build_share_source_sheet": "Build & share source sheets",
"model.sign_up.add_to_sheet.connect_with_other_users": "Connect with other users",
"model.sign_up.add_to_sheet.create_free_accout_to_join_conversation": "Create a free account to join the conversation",
"model.sign_up.add_to_sheet.want_to_make_your_own_source_sheet": "Want to make your own source sheet?",
"model.sign_up.add_translation.create_free_account__to_add_it_to_library": "Create a free account to add it to the library & do more on Sefaria",
"model.sign_up.add_translation.create_free_account__to_add_it_to_library": "Create a free account to add it to the library & do more on Pecha",
"model.sign_up.add_translation.have_your_own_translation_of_this_text": "Have your own translation of this text?",
"model.sign_up.follow.follow_your_favorite_creaters": "Follow your favorite creators",
"model.sign_up.follow.send_messages": "Send messages",
"model.sign_up.follow.want_to_connect_with_other_users": "Want to connect with other Sefaria users?",
"model.sign_up.follow.want_to_connect_with_other_users": "Want to connect with other Pecha users?",
"model.sign_up.note.dont_lose_that_thought": "Don’t lose that thought!",
"model.sign_up.note.get_updates_on_new_features": "Get updates on new features",
"model.sign_up.note.take_notes_on_this_text": "Take notes on this text",
Expand All @@ -378,9 +382,11 @@
"portuguese": "Portuguese",
"profile.all_time": "All Time",
"profile.at": "at",
"profile.averages_pecha_user": "Average Sefaria User",
"profile.averages_pecha_user": "Average Pecha User",
"profile.buddhish_text_tracker": "Buddhist Text Tracker",
"profile.collection_description": "You can use collections to organize your sheets or public sheets you like. Collections can shared privately or made public on Sefaria.",
"profile.buddhist_tracker.favorite_sheets": "Your Favorite Sheets",
"profile.buddhist_tracker.favorite_texts": "Your Favorite Texts",
"profile.collection_description": "You can use collections to organize your sheets or public sheets you like. Collections can shared privately or made public on Pecha.",
"profile.edit_profile": "Edit Profile",
"profile.etc": "Etc",
"profile.log_out": "Log Out",
Expand All @@ -394,7 +400,7 @@
"profile.sheet_read": "Sheets Read",
"profile.tab.button.create_New_Sheet": "Create a New Sheet",
"profile.tab.collection": "Collections",
"profile.tab.collection.description": "You can use collections to organize your sheets or public sheets you like. Collections can be shared privately or made public on Sefaria",
"profile.tab.collection.description": "You can use collections to organize your sheets or public sheets you like. Collections can be shared privately or made public on Pecha",
"profile.tab.dropdown.sort": "Sort",
"profile.tab.dropdown.sort_by": "Sort by",
"profile.tab.sheets": "Sheets",
Expand Down Expand Up @@ -474,6 +480,8 @@
"sheet.delete_sheet": "Delete Sheet",
"sheet.delete_warning_msg": "Are you sure you want to delete this sheet? There is no way to undo this action.",
"sheet.edit": "Edit",
"sheet.editor.source.input_field.placeholder": "Search for a Text or Commentator.",
"sheet.editor.untitled": "untitled",
"sheet.editor.view_in_editor": "View In Editor",
"sheet.editor.write_something": "Write something...",
"sheet.edit_source_title": "Edit Source title",
Expand All @@ -487,7 +495,7 @@
"sheet.insert": "Insert",
"sheet.liked_your_sheet": "liked your sheet",
"sheet.list_on_pecha": "List on Pecha",
"sheet.list_your_sheet": "List your sheet on Sefaria for others to discover.",
"sheet.list_your_sheet": "List your sheet on Pecha for others to discover.",
"sheet.loading_sheet": "Loading your sheets",
"sheet.looking_up_connection": "Looking up Connections...",
"sheet.make_public": "Make Public",
Expand All @@ -514,6 +522,7 @@
"sheet.placeholder.add_topic": "Add Topic",
"sheet.print": "Print",
"sheet.public_source_sheet": "Public Source Sheets",
"sheet.published": "Published",
"sheet.publish_new_sheet": "published a new sheet",
"sheet.publish_setting": "Publish Settings",
"sheet.publish_sheet_on_pecha": "Publish your sheet on Pecha for others to discover.",
Expand Down Expand Up @@ -569,6 +578,7 @@
"side_nav.about_pecha_description": "Pecha connects users to Buddhist scriptures in various languages. Search a verse to explore its origins, interpretations, and related texts. Engage with the community by sharing insights and learning from others through sheets and topics.",
"side_nav.about_pecha_title": "A Living Library of Buddhist Text",
"side_nav.about_text": "About This Text",
"side_nav.catetory.about_category": "About {{category_name}}",
"side_nav.collection.description": "Organizations, communities and individuals around the world curate and share collections of sheets for you to explore.",
"side_nav.community.join_conversation": "Join the Conversation",
"side_nav.download_text": "Download Text",
Expand Down Expand Up @@ -634,6 +644,8 @@
"text.edit.translation_language:": "Translation language:",
"text.edit.translation_title": "Translation Title:",
"text.english_version": "English Versions",
"text.error.message.something_went_wrong": "Something went wrong! Please use the back button or the menus above to get back on track.",
"text.error.message.text_not_accessible": " You do not have access permission to this text",
"text.feedback.describe_issue": "Describe the issue...",
"text.feedback.feedback_send": "feedback sent",
"text.feedback.get_help": "Get help",
Expand Down Expand Up @@ -666,16 +678,20 @@
"text.reader_option_menu.show_only_vowels": "Show only vowel points",
"text.reader_option_menu.show_puntuation": "Show Punctuation",
"text.reader_option_menu.show_vowels": "Show Vowels and Cantillation",
"text.reader_option_menu.source": "Source",
"text.reader_option_menu.source_with_translation": "Source with Translation",
"text.reader_option_menu.translation": "Translation",
"text.reader_option_menu.vocalization": "Vocalization",
"text.reader_option_menu.vowels": "Vowels",
"text.reference": "Reference",
"text.related Passage": "Related Passage",
"text.related_texts": "Related Texts",
"text.removed.modal.message": "Remove{text}",
"text.root_text": "Root Text",
"text.saved.modal.message": "Save {text}",
"text.save_text": "Save texts",
"text.save_texts": "Save texts",
"text._sefaria_linker": "Sefaria Linker",
"text._sefaria_linker": "Pecha Linker",
"text.selected_citation": "Selected Citation",
"text.share_link": "SHARE LINK",
"text.show_all_commnentaries": "Show all commentaries",
Expand Down Expand Up @@ -737,6 +753,7 @@
"topic.admin.title_must_be_provided": "Title must be provided",
"topic.admin.topic_editor": "Topic Editor",
"topic.all_topics": "All Topics",
"topic.alphabet": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"topic.a_to_z": "All Topics A-Z",
"topic.browse_topic": "Browse or search out complete list of topics.",
"topic.combine_source": "Combine sources from our library with your own comments, questions, images, and videos.",
Expand Down Expand Up @@ -766,4 +783,4 @@
"website.pecha.version": "Version: 1.4.0",
"write_short_description": "Write a short description of your sheet...",
"yiddish": "Yiddish"
}
}
11 changes: 0 additions & 11 deletions src/utils/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,3 @@ export const ACCESS_TOKEN = "accessToken";
export const RESET_PASSWORD_TOKEN = "resetPasswordToken";
export const RESET_PASSWORD = "reset-password";
export const LANGUAGE = "language";

const ALPHABETS = {
en: "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),
"bo-IN": "ཀཁགངཅཆཇཉཏཐདནཔཕབམཙཚཛཝཞཟའཡརལཤསཧཨ".split(""),
};

const DEFAULT_LANGUAGE = "bo-IN";

export const getAlphabet = (language) => {
return ALPHABETS[language] || ALPHABETS[DEFAULT_LANGUAGE];
};

0 comments on commit 6f1f4f7

Please sign in to comment.