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

742 use localizations (Core localizations) #1098

Merged
merged 19 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
12a77a1
Merge branch 'main' into 742-use-localizations
katherinejensen00 Jul 16, 2024
2e5a6b7
Switching Computers Partial Commit
katherinejensen00 Aug 21, 2024
ae5ae18
Merge branch 'main' into 742-use-localizations
katherinejensen00 Aug 23, 2024
6e0a562
Paranext Core localizations
katherinejensen00 Aug 30, 2024
eeff67e
Merge branch 'main' into 742-use-localizations
katherinejensen00 Aug 30, 2024
bf47710
Changes per Ira's code review
katherinejensen00 Sep 3, 2024
fc6c1f0
Alphabetize and create more specific localize keys
katherinejensen00 Sep 6, 2024
6b1c89e
Missed a file
katherinejensen00 Sep 6, 2024
0170a75
Add one localization
katherinejensen00 Sep 13, 2024
089a78e
Merge branch 'main' into 742-use-localizations
katherinejensen00 Oct 1, 2024
b38b61e
Merge branch 'main' into 742-use-localizations
katherinejensen00 Oct 1, 2024
e7ebfbe
Changes per code review mostly reverting localize key changes of alre…
katherinejensen00 Oct 15, 2024
86946ad
Merge branch 'main' into 742-use-localizations
katherinejensen00 Oct 15, 2024
2346d38
Merge branch 'main' into 742-use-localizations
katherinejensen00 Oct 16, 2024
a3d5791
Fix failing tests
katherinejensen00 Oct 16, 2024
cedca4b
Changes per code review - removing unnecessary useMemos and reverting…
katherinejensen00 Oct 25, 2024
9652a61
Changes per code review
katherinejensen00 Nov 8, 2024
52296e1
Changes per code review
katherinejensen00 Nov 8, 2024
95b20ab
Merge branch 'main' into 742-use-localizations
katherinejensen00 Nov 8, 2024
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
41 changes: 41 additions & 0 deletions assets/localization/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
{
"%product_name%": "Platform.Bible",
"%bookSelector_chooseEllipsis%": "Choose...",
"%bookSelector_chooseBooks%": "Choose Books",
"%bookSelector_currentBook%": "Current Book",
"%bookSelector_selectBooks%": "Select Books",
"%bookSelector_selectOneOrMoreBooksToRunBasicChecksOn%": "Select one or more books to run basic checks on",
"%checks_Capitalization%": "Capitalization",
"%checks_chapterSlashVerseNumbers%": "Chapter/Verse Numbers",
"%checks_charactersParenthesesCombinations%": "Characters (Combinations)",
"%checks_checks%": "Checks",
"%checks_footnoteQuotes%": "Footnote Quotes",
"%checks_markers%": "Markers",
"%checks_noCurrentProject%": "No current project",
"%checks_numbers%": "Numbers",
"%checks_punctuationParenthesesSequences%": "Punctuation (Sequences)",
"%checks_quotations%": "Quotations",
"%checks_quotationTypes%": "Quotation types",
"%checks_references%": "References",
"%checks_repeatedWords%": "Repeated Words",
"%checks_runBasicChecks%": "Run Basic Checks",
"%checks_unmatchedPairsOfPunctuation%": "Unmatched Pairs of Punctuation",
"%downloadUpdateProjectTab_aria_downloadableProjects%": "downloadable projects",
"%downloadUpdateProjectTab_aria_downloadedProjects%": "downloaded projects",
"%downloadUpdateProjectTab_listItem_delete%": "Delete",
"%downloadUpdateProjectTab_subheader_downloadableProjects%": "Downloadable Projects",
"%downloadUpdateProjectTab_subheader_downloadedProjects%": "Downloaded Projects",
"%downloadUpdateProjectTab_title_downloadSlashUpdateProject%": "Download/Update Project",
"%general_cancel%": "Cancel",
"%general_loading%": "Loading",
"%general_run%": "Run",
"%insertNote%": "Insert Note",
"%mainMenu_aboutPlatformBible%": "About Platform.Bible",
"%mainMenu_downloadSlashInstallResources%": "Download/Install Resources",
Expand All @@ -14,17 +43,29 @@
"%mainMenu_window%": "Window",
"%some_localization_key%": "This is the English text for %some_localization_key%.",
"%submitButton%": "Submit",
"%tab_error%": "Error",
"%tab_unknown%": "Unknown",
"%tabAria_tab%": "Tab",
"%webView_edit%": "Edit",
"%webView_openProjectSettings%": "Open Project Settings",
"%webView_project%": "Project",
"%webView_projectAssignmentsAndProgress%": "Assignments and Progress",
"%webView_defaultTitle_webView%": "Web View",
"%wordList%": "Word List",
"%selectBooks_selectBooks%": "Select Books",
"%selectProject_selectProject%": "Select Project",
"%selectMultipleProjects_selectProjects%": "Select Projects",
"%settings_loadingSetting%": "Loading setting",
"%settings_platform_group1_label%": "Platform Settings",
"%settings_searchProjectSettingsEllipsis%": "Search Project Settings...",
"%settings_searchUserSettingsEllipsis%": "Search User Settings...",
"%settings_platform_group1_description%": "Settings pertaining to the software overall",
"%settings_platform_verseRef_label%": "Current Verse Reference",
"%settings_platform_interfaceLanguage_label%": "Interface Language",
"%settings_platform_ptxUtilsMementoData_label%": "PtxUtils Memento Data",
"%settings_platform_paratextDataLastRegistryDataCachedTimes_label%": "ParatextData Last Registry Data Cached Times",
"%settings_projectSettings%": "Project Settings",
"%settings_userSettings%": "User Settings",
"%project_settings_platform_group1_label%": "Platform Settings",
"%project_settings_platform_group1_description%": "Project settings pertaining to the software overall",
"%project_settings_platform_name_label%": "Project Short Name",
Expand Down
30 changes: 28 additions & 2 deletions extensions/src/hello-world/contributions/localizedStrings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,36 @@
"%mainMenu_openHelloWorldProject%": "Open Hello World Project",
"%mainMenu_createNewHelloWorldProject%": "Create New Hello World Project",
"%mainMenu_deleteHelloWorldProject%": "Delete Hello World Project",
"%helloWorld_webViewMenu_project%": "Project",
"%helloWorld_webViewMenu_view%": "View",
"%helloSomeone_greetingLoading%": "Greeting loading",
"%helloWorld_delete%": "Delete",
"%helloWorld_frenchLocalizationSubmit%": "French localization of Submit Button",
"%helloWorld_helloWorld%": "Hello World",
"%helloWorld_listOfSelectedIds%": "List of Selected Project Id(s)",
"%helloWorld_logo%": "Hello World Logo",
"%helloWorld_none%": "None",
"%helloWorld_openResourceViewer%": "Open in Resource Viewer",
"%helloWorld_openScriptureEditor%": "Open in Scripture Editor",
"%helloWorld_option1%": "Option 1",
"%helloWorld_option2%": "Option 2",
"%helloWorld_react%": "React",
"%helloWorld_select_project%": "Select Project",
"%helloWorld_select_projects%": "Select Projects",
"%helloWorld_selected_project%": "Selected Project",
"%helloWorld_table_id%": "ID",
"%helloWorld_table_subtitle%": "Subtitle",
"%helloWorld_table_title%": "Title",
"%helloWorld_testMe%": "Test Me",
"%helloWorld_throw_test_exception%": "Throw test exception",
"%helloWorld_webViewMenu_deleteProject%": "Delete this Project",
"%helloWorld_webViewMenu_openViewer%": "Open Viewer",
"%helloWorld_webViewMenu_project%": "Project",
"%helloWorld_webViewMenu_view%": "View",
"%quickVerse_loadingLatest%": "Loading latest Scripture text...",
"%scripture_loadingVerse%": "Loading Verse",
"%selectProject_prompt%": "Please select a Scripture project for Hello World WebView: (Render",
"%selectProject_title%": "Select Hello World Project",
"%selectProjects_prompt%": "Please select one or more Scripture projects for Hello World WebView:",
"%selectProjects_title%": "Select List of Hello World Projects",
"%settings_hello_world_group1_label%": "Hello World Settings",
"%settings_hello_world_personName_label%": "Selected Person's Name on Hello World Web View",
"%project_settings_helloWorld_group1_label%": "Hello World Project Settings",
Expand Down
150 changes: 118 additions & 32 deletions extensions/src/hello-world/src/web-views/hello-world.web-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,89 @@ globalThis.webViewComponent = function HelloWorld({
[scrRef],
);

const deleteKey = '%helloWorld_delete%';
const frenchLocalizationSubmit = '%helloWorld_frenchLocalizationSubmit%';
const greetingLoading = '%helloSomeone_greetingLoading%';
const helloWorld = '%helloWorld_helloWorld%';
const listOfSelectedIds = '%helloWorld_listOfSelectedIds%';
const logoKey = '%helloWorld_logo%';
const noneKey = '%helloWorld_none%';
const openResourceViewer = '%helloWorld_openResourceViewer%';
const openScriptureEditor = '%helloWorld_openScriptureEditor%';
const option1 = '%helloWorld_option1%';
const option2 = '%helloWorld_option2%';
const quickVerseLoadingLatest = '%quickVerse_loadingLatest%';
const reactKey = '%helloWorld_react%';
const scriptureLoadingVerse = '%scripture_loadingVerse%';
const selectedProjectKey = '%helloWorld_selected_project%';
const selectProjectKey = '%helloWorld_select_project%';
const selectProjectPrompt = '%selectProject_prompt%';
const selectProjectsKey = '%helloWorld_select_projects%';
const selectProjectsPrompt = '%selectProjects_prompt%';
const selectProjectsTitle = '%selectProjects_title%';
const selectProjectTitle = '%selectProject_title%';
const submit = '%submitButton%';
const testException = '%helloWorld_throw_test_exception%';
const testMe = '%helloWorld_testMe%';

const [localizedStrings] = useLocalizedStrings(
useMemo(
() => [
deleteKey,
frenchLocalizationSubmit,
greetingLoading,
helloWorld,
listOfSelectedIds,
logoKey,
noneKey,
openResourceViewer,
openScriptureEditor,
option1,
option2,
quickVerseLoadingLatest,
reactKey,
scriptureLoadingVerse,
selectedProjectKey,
selectProjectKey,
selectProjectPrompt,
selectProjectsKey,
selectProjectsPrompt,
selectProjectsTitle,
selectProjectTitle,
submit,
testException,
testMe,
],
[],
),
useMemo(() => ['fr', 'en'], []),
);

const localizedDelete = localizedStrings[deleteKey];
const localizedFrenchLocalizationSubmit = localizedStrings[frenchLocalizationSubmit];
const localizedGreetingLoading = localizedStrings[greetingLoading];
const localizedHelloWorld = localizedStrings[helloWorld];
const localizedListOfSelectedIds = localizedStrings[listOfSelectedIds];
const localizedLogo = localizedStrings[logoKey];
const localizedNone = localizedStrings[noneKey];
const localizedOpenResourceViewer = localizedStrings[openResourceViewer];
const localizedOpenScriptureEditor = localizedStrings[openScriptureEditor];
const localizedOption1 = localizedStrings[option1];
const localizedOption2 = localizedStrings[option2];
const localizedQuickVerseLoadingLatest = localizedStrings[quickVerseLoadingLatest];
const localizedReact = localizedStrings[reactKey];
const localizedScriptureLoadingVerse = localizedStrings[scriptureLoadingVerse];
const localizedSelectedProject = localizedStrings[selectedProjectKey];
const localizedSelectProject = localizedStrings[selectProjectKey];
const localizedSelectProjectPrompt = localizedStrings[selectProjectPrompt];
const localizedSelectProjects = localizedStrings[selectProjectsKey];
const localizedSelectProjectsPrompt = localizedStrings[selectProjectsPrompt];
const localizedSelectProjectsTitle = localizedStrings[selectProjectsTitle];
const localizedSelectProjectTitle = localizedStrings[selectProjectTitle];
const localizedSubmit = localizedStrings[submit];
const localizedTestException = localizedStrings[testException];
const localizedTestMe = localizedStrings[testMe];

// Update the clicks when we are informed helloWorld has been run
useEvent(
papi.network.getNetworkEvent('helloWorld.onHelloWorld'),
Expand All @@ -66,8 +149,8 @@ globalThis.webViewComponent = function HelloWorld({

useEffect(() => {
logger.debug(`Hello World WebView previous title: ${title}`);
updateWebViewDefinition({ title: `Hello World ${clicks}` });
}, [title, updateWebViewDefinition, clicks]);
updateWebViewDefinition({ title: `${localizedHelloWorld} ${clicks}` });
}, [title, updateWebViewDefinition, localizedHelloWorld, clicks]);

const currentRender = useRef(-1);
currentRender.current += 1;
Expand All @@ -77,9 +160,9 @@ globalThis.webViewComponent = function HelloWorld({
// This is intentionally not a stable reference like `useMemo` or something because we are
// testing below to make sure `useDialogCallback` returns the same callback every time
{
prompt: `Please select a Scripture project for Hello World WebView: (Render ${currentRender.current})`,
prompt: `${localizedSelectProjectPrompt} ${currentRender.current})`,
iconUrl: 'papi-extension://helloWorld/assets/offline.svg',
title: 'Select Hello World Project',
title: localizedSelectProjectTitle,
maximumOpenDialogs: 2,
// Test ref parameter properly getting latest value
currentRender: currentRender.current,
Expand Down Expand Up @@ -116,7 +199,7 @@ globalThis.webViewComponent = function HelloWorld({

const [latestVerseText] = useData('quickVerse.quickVerse').Verse(
'latest',
'Loading latest Scripture text...',
localizedQuickVerseLoadingLatest,
);

const [projects, setProjects] = useWebViewState<string[]>('projects', []);
Expand All @@ -125,13 +208,13 @@ globalThis.webViewComponent = function HelloWorld({
'platform.selectMultipleProjects',
useMemo(
() => ({
prompt: 'Please select one or more Scripture projects for Hello World WebView:',
prompt: `${localizedSelectProjectsPrompt}`,
iconUrl: 'papi-extension://helloWorld/assets/offline.svg',
title: 'Select List of Hello World Projects',
title: localizedSelectProjectsTitle,
selectedProjectIds: projects,
includeProjectInterfaces: ['platformScripture.USFM_Verse'],
}),
[projects],
[localizedSelectProjectsPrompt, localizedSelectProjectsTitle, projects],
),
useCallback(
(selectedProjects) => {
Expand Down Expand Up @@ -168,34 +251,33 @@ globalThis.webViewComponent = function HelloWorld({

const peopleDataProvider = useDataProvider('helloSomeone.people');

const [personGreeting] = useData('helloSomeone.people').Greeting(name, 'Greeting loading');
const [personGreeting] = useData('helloSomeone.people').Greeting(name, localizedGreetingLoading);

const [personAge] = useData('helloSomeone.people').Age(name, -1);

const [currentProjectVerse] = useProjectData(
'platformScripture.USFM_Verse',
projectId ?? undefined,
).VerseUSFM(verseRef, 'Loading Verse');
).VerseUSFM(verseRef, localizedScriptureLoadingVerse);

const helloWorldProjectSettings = useHelloWorldProjectSettings(projectId);
const { headerStyle } = helloWorldProjectSettings;
const [localizedStrings] = useLocalizedStrings(
useMemo(() => ['%submitButton%'], []),
useMemo(() => ['fr', 'en'], []),
);

const localizedString = localizedStrings['%submitButton%'];
const genericComboBoxOptions = useMemo(
() => [localizedOption1, localizedOption2],
[localizedOption1, localizedOption2],
);

return (
<div>
<div className="title">
Hello World <span className="framework">React</span>
{localizedHelloWorld} <span className="framework">{localizedReact}</span>
{/**
* Note: `Logo` here is inlined into this code as a `data:` url. This is here simply for
* demonstration purposes. Inlining as a `data:` url is generally not recommended. Rather, it is
* generally better to use `papi-extension:` to avoid unnecessary bloat
*/}
<img width={16} height={16} src={`${Logo}`} alt="Hello World Logo" />
<img width={16} height={16} src={`${Logo}`} alt={localizedLogo} />
</div>
<div>
<Button
Expand All @@ -207,7 +289,7 @@ globalThis.webViewComponent = function HelloWorld({
.catch((e) => logger.error(`Could not get data from example.com! Reason: ${e}`));
}}
>
Hello World {clicks}
{localizedHelloWorld} {clicks}
</Button>
</div>
<div>
Expand All @@ -216,58 +298,62 @@ globalThis.webViewComponent = function HelloWorld({
throw new Error(`${NAME} test exception!`);
}}
>
Throw test exception
{localizedTestException}
</Button>
</div>
<div>{latestVerseText}</div>
<Clock />
<div>
<input value={nameTemp} onChange={(e) => setName(e.target.value)} />
<Button onClick={() => peopleDataProvider?.deletePerson(name)}>Delete {name}</Button>
<Button onClick={() => peopleDataProvider?.deletePerson(name)}>
{localizedDelete} {name}
</Button>
</div>
<div>{personGreeting}</div>
<div>{personAge}</div>
<br />
<div>Selected Project: {projectId ?? 'None'}</div>
<div>
<Button onClick={selectProject}>Select Project</Button>
{localizedSelectedProject}: {projectId ?? localizedNone}
</div>
<div>
<Button onClick={selectProject}>{localizedSelectProject}</Button>
</div>
<div>
<Button
onClick={() =>
papi.commands.sendCommand('platformScriptureEditor.openScriptureEditor', projectId)
}
>
Open in Scripture Editor
{localizedOpenScriptureEditor}
</Button>
<Button
onClick={() =>
papi.commands.sendCommand('platformScriptureEditor.openResourceViewer', projectId)
}
>
Open in Resource Viewer
{localizedOpenResourceViewer}
</Button>
</div>
<h3 style={headerStyle}>{verseRef.toString()}</h3>
<div>{currentProjectVerse}</div>
<ProjectSettingsEditor {...helloWorldProjectSettings} />
<h3>List of Selected Project Id(s):</h3>
<div>{(projects.length > 0 ? projects : ['None']).join(', ')}</div>
<h3>{localizedListOfSelectedIds}:</h3>
<div>{(projects.length > 0 ? projects : [{ localizedNone }]).join(', ')}</div>
<div>
<Button onClick={() => selectProjects()}>Select Projects</Button>
<Button onClick={() => selectProjects()}>{localizedSelectProjects}</Button>
</div>
<br />
<div>
<TextField label="Test Me" />
<Checkbox labelText="Test Me" />
<TextField label={localizedTestMe} />
<Checkbox labelText={localizedTestMe} />
<Switch /> {/* no label available */}
<ComboBox title="Test Me" options={['option 1', 'option 2']} />
<ComboBox title={localizedTestMe} options={genericComboBoxOptions} />
<Slider /> {/* no label available */}
<BookChapterControl scrRef={scrRef} handleSubmit={(newScrRef) => setScrRef(newScrRef)} />
</div>
<div>
<h3>French localization of Submit Button:</h3>
<div>{localizedString}</div>
<h3>{localizedFrenchLocalizationSubmit}:</h3>
<div>{localizedSubmit}</div>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"%webView_platformScriptureEditor_runBasicChecks%": "Run Basic Checks...",
"%webView_platformScriptureEditor_publisherInfo%": "Publisher Info",
"%webView_platformScriptureEditor_copyrightInfo%": "Copyright Info",
"%webView_platformScriptureEditor_editable%": "(Editable)",
"%webView_platformScriptureEditor_resourceViewer%": "Resource Viewer",
"%webView_platformScriptureEditor_scriptureEditor%": "Scripture Editor",
"%platformScriptureEditor_dialog_openResourceViewer_title%": "Open Resource Viewer",
"%platformScriptureEditor_dialog_openResourceViewer_prompt%": "Choose a resource to open:",
"%platformScriptureEditor_dialog_openScriptureEditor_title%": "Open Scripture Editor",
Expand Down
Loading
Loading