Skip to content

Commit

Permalink
Even more Hebrew
Browse files Browse the repository at this point in the history
  • Loading branch information
ronshapiro committed Jan 19, 2025
1 parent 77b0864 commit afd5bcb
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 24 deletions.
2 changes: 1 addition & 1 deletion js/CommentEditorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function CommentEditorModal(): React.ReactElement | null {
content={(
<ModalEditor
title={data.title}
titleHebrew={data.title}
titleHebrew={data.titleHebrew}
onSubmit={(event) => onSubmit(event)}
direction={direction}
textAreaRef={ref}
Expand Down
2 changes: 1 addition & 1 deletion js/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ interface TextDirectionButton {
directionButton: React.ReactElement;
}
export function useTextDirectionButton(): TextDirectionButton {
const [isRtl, setIsRtl] = useState(false);
const [isRtl, setIsRtl] = useState(localStorage.languageOption === "hebrew");
const button = (
<button
key="direction"
Expand Down
5 changes: 3 additions & 2 deletions js/NavigationButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ interface ButtonProps {
navigationExtension: NavigationExtension;
}

// TODO(language): the pageText still could be localized, need to consider how to do that best.
function loadText(pageText: string): string {
return localStorage.languageOption === "hebrew"
? `לטעון ${pageText.replace(/_/g, " ")}`
Expand All @@ -99,7 +100,7 @@ export const PreviousButton = (props: ButtonProps): React.ReactElement | null =>
return (
<NavigationButtonRow
isNext={false}
text={loadText(navigationExtension.previous())}
text={loadText(navigationExtension.displayPrevious())}
doLoad={() => navigationExtension.loadPrevious()}
defaultEditText={() => navigationExtension.defaultEditText()}
/>
Expand All @@ -118,7 +119,7 @@ export const NextButton = (props: ButtonProps): React.ReactElement | null => {
return (
<NavigationButtonRow
isNext
text={loadText(navigationExtension.next())}
text={loadText(navigationExtension.displayNext())}
doLoad={() => navigationExtension.loadNext()}
defaultEditText={() => navigationExtension.defaultEditText()}
/>
Expand Down
3 changes: 3 additions & 0 deletions js/NavigationExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export interface BaseNavigationExtension {
previous: NullaryFunction<string>;
next: NullaryFunction<string>;

displayPrevious: NullaryFunction<string>;
displayNext: NullaryFunction<string>;

hasPrevious: NullaryFunction<boolean>;
hasNext: NullaryFunction<boolean>;
}
Expand Down
9 changes: 7 additions & 2 deletions js/Renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,14 @@ export abstract class Renderer {
}

export function numericalNavigationExtension (): BaseNavigationExtension {
const previous = () => (parseInt(amudMetadata().amudStart!) - 1).toString();
const next = () => (parseInt(amudMetadata().amudEnd!) + 1).toString();
return {
previous: () => (parseInt(amudMetadata().amudStart!) - 1).toString(),
next: () => (parseInt(amudMetadata().amudEnd!) + 1).toString(),
previous,
next,

displayPrevious: previous,
displayNext: next,

hasPrevious: () => amudMetadata().amudStart !== "1",
hasNext: () => {
Expand Down
7 changes: 6 additions & 1 deletion js/corrections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import {snackbars} from "./snackbar";

export function postCorrection(data: Omit<CorrectionPostData, "user">): Promise<unknown> {
const {ref, userText} = data;
snackbars.reportedIssueSent.show(`Posted correction on ${ref}: ${userText}`, []);
snackbars.reportedIssueSent.show(
localStorage.languageOption === "hebrew"
// TODO(language): ref should be localized
? `תיקון של ${ref} נשלח`
: `Posted correction on ${ref}: ${userText}`,
[]);

const promise = postWithRetry("/corrections", {
...data,
Expand Down
16 changes: 13 additions & 3 deletions js/page_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ export class Runner {
removeLast: () => this.removeLastSection(),
defaultEditText: () => bookTitleAndRange(),
});
if (!renderer.navigationExtension.displayNext) {
renderer.navigationExtension.displayNext = renderer.navigationExtension.next;
}
if (!renderer.navigationExtension.displayPrevious) {
renderer.navigationExtension.displayPrevious = renderer.navigationExtension.previous;
}
this.apiCache = new ApiCache();
this.requestQueue = new PromiseQueue(5);
timeoutPromise(5000).then(() => this.apiCache.purge());
Expand Down Expand Up @@ -274,13 +280,17 @@ export class Runner {
return;
}

snackbars.googleSignIn.show("Save notes to Google Drive?", [
const useHebrew = localStorage.languageOption === "hebrew";
const snackbarText = useHebrew ? "לשמור הערות לGoogle Drive?" : "Save notes to Google Drive?";
const noThanks = useHebrew ? "לא תודה" : "No thanks";
const signIn = useHebrew ? "להכנס" : "Sign in";
snackbars.googleSignIn.show(snackbarText, [
{
text: "No thanks",
text: noThanks,
onClick: () => snackbars.googleSignIn.dismissButtonImpl(),
},
{
text: "Sign in",
text: signIn,
onClick: () => {
snackbars.googleSignIn.hide();
this.driveClient.signIn();
Expand Down
1 change: 1 addition & 0 deletions js/ref_selection_snackbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ const onSelectionChange = () => {
|| window.location.pathname.startsWith("/BirkatHamazon")
);
})();
// TODO(language): localizeRef
snackbars.textSelection.show(hideRef ? "" : ref, buttons);
};

Expand Down
25 changes: 17 additions & 8 deletions js/snackbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,35 +271,44 @@ export const snackbars = new SnackbarManager();
$(document).ready(() => {
moveSnackbarOffscreen();

const useHebrew = localStorage.languageOption === "hebrew";
const updatedOptions = useHebrew ? "בדקו הגדרות חדשות" : "Check out the updated options!";
const availableOptions = useHebrew ? "בדקו הגדרות אפשריות" : "Check out the available options!";

snackbars.preferencesNudge.show(
(hasSeenLatestPreferences()
? "Check out the updated options!"
: "Check out the available options!"),
(hasSeenLatestPreferences() ? updatedOptions : availableOptions),
[
{
text: "Preferences",
text: useHebrew ? "הגדרות" : "Preferences",
onClick: () => {
gtag("event", "snackbar.preferencesPage.clicked");
(window as any).showPreferences();
},
},
{
text: "Dismiss",
text: useHebrew ? "סגור" : "Dismiss",
onClick: () => snackbars.preferencesNudge.dismissButtonImpl(),
},
]);

const shareData = {url: "https://talmud.page"};
if (navigator.canShare && navigator.canShare(shareData)) {
const text = [
const textEnglish = [
"Share talmud.page with a friend?",
"Know someone who would enjoy learning here?",
"Spread the talmud.page love!",
"talmud.page isn't well known. Help change that?",
].sort(() => Math.random() - .5)[0];
];
const textHebrew = [
"שתף talmud.page עם חבר/ה?",
"מכירים מישהו שיאהב ללמוד פה?",
"להפיץ את האהבה של talmud.page!",
"talmud.page עוד לא מוכר. רוצה לשנות את זה?",
];
const text = (useHebrew ? textHebrew : textEnglish).sort(() => Math.random() - .5)[0];
snackbars.share.show(text, [
{
text: "Dismiss",
text: useHebrew ? "סגור" : "Dismiss",
onClick: () => {
sendEvent({share: false, text, subject: "Share dismissed"});
snackbars.share.dismissButtonImpl();
Expand Down
14 changes: 8 additions & 6 deletions js/talmud_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ import {amudMetadata, computePreviousAmud, computeNextAmud} from "./amud.ts";
import {driveClient} from "./google_drive/singleton.ts";
import {Runner} from "./page_runner.js";
import {formatDafInHebrew} from "../talmud.ts";
import {intToHebrewNumeral, ALEPH, BET} from "../hebrew";

function translatePage(page) {
const number = page.slice(0, -1);
const aOrB = page.endsWith("a") ? ALEPH : BET;
return `${intToHebrewNumeral(parseInt(number))} ע"${aOrB}`;
return formatDafInHebrew("", page).slice(1);
}

const previous = () => computePreviousAmud(amudMetadata().amudStart);
const next = () => computeNextAmud(amudMetadata().amudEnd);

class TalmudRenderer extends Renderer {
constructor() {
super(
getCommentaryTypes("talmud"),
{
previous: () => translatePage(computePreviousAmud(amudMetadata().amudStart)),
next: () => translatePage(computeNextAmud(amudMetadata().amudEnd)),
previous,
next,
displayPrevious: () => translatePage(previous()),
displayNext: () => translatePage(next()),

hasPrevious: () => {
const metadata = amudMetadata();
Expand Down

0 comments on commit afd5bcb

Please sign in to comment.