Skip to content

Commit

Permalink
Added platformScripture settings
Browse files Browse the repository at this point in the history
  • Loading branch information
tjcouch-sil committed Apr 16, 2024
1 parent f01189a commit f106a34
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 56 deletions.
4 changes: 2 additions & 2 deletions assets/localization/eng.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"project_settings_platform_group1_description": "Project settings pertaining to the software overall",
"project_settings_platform_fullName_label": "Project Full Name",
"project_settings_platform_language_label": "Project Primary Language",
"project_settings_platform_booksPresent_label": "Scripture Books Present",
"project_settings_platform_booksPresent_description": "Which books of the Bible are present in this Scripture project",
"project_settings_platformScripture_booksPresent_label": "Scripture Books Present",
"project_settings_platformScripture_booksPresent_description": "Which books of the Bible are present in this Scripture project",
"project_settings_platformScripture_versification_label": "Scripture Versification",
"project_settings_platformScripture_versification_description": "Which versification scheme this Scripture project follows"
}
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
[]
[
{
"label": "%project_settings_platformScripture_group1_label%",
"properties": {
"platformScripture.booksPresent": {
"label": "%project_settings_platformScripture_booksPresent_label%",
"description": "%project_settings_platformScripture_booksPresent_description%",
"default": "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"includeProjectTypes": ["Paratext", "Scripture"]
},
"platformScripture.versification": {
"label": "%project_settings_platformScripture_versification_label%",
"description": "%project_settings_platformScripture_versification_description%",
"default": 4,
"includeProjectTypes": ["Paratext", "Scripture"]
}
}
}
]
38 changes: 36 additions & 2 deletions extensions/src/platform-scripture/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
import { logger } from '@papi/backend';
import papi, { logger } from '@papi/backend';
import { ExecutionActivationContext, ProjectSettingValidator } from '@papi/core';

export async function activate() {
// #region Project Setting Validators

// Based on https://github.com/paranext/paranext-core/blob/5c403e272b002ddd8970f735bc119f335c78c509/extensions/src/usfm-data-provider/index.d.ts#L401
// Should be 123 characters long
const booksPresentValidator: ProjectSettingValidator<'platformScripture.booksPresent'> = async (
newValue: string,
): Promise<boolean> => {
return newValue.length === 123 && newValue.replace(/[01]/g, '').length === 0;
};

// Based on https://github.com/paranext/paranext-core/blob/5c403e272b002ddd8970f735bc119f335c78c509/extensions/src/usfm-data-provider/index.d.ts#L391
// There are 7 options in the enum
const versificationValidator: ProjectSettingValidator<'platformScripture.versification'> = async (
newValue: number,
): Promise<boolean> => {
return typeof newValue === 'number' && newValue >= 0 && newValue <= 6;
};

// #endregion

export async function activate(context: ExecutionActivationContext) {
logger.info('platformScripture is activating!');

const booksPresentPromise = papi.projectSettings.registerValidator(
'platformScripture.booksPresent',
booksPresentValidator,
);
const versificationPromise = papi.projectSettings.registerValidator(
'platformScripture.versification',
versificationValidator,
);

context.registrations.add(await booksPresentPromise, await versificationPromise);

logger.info('platformScripture is finished activating!');
}

export async function deactivate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,27 @@ declare module 'platform-scripture' {
// Add extension types exposed on the papi for other extensions to use here
// More instructions can be found in the README
}

declare module 'papi-shared-types' {
export interface ProjectSettingTypes {
/**
* Which versification scheme this Scripture project uses
*
* WARNING: This setting is an example and needs to be updated to support proper versification
* specification! For the moment, it simply corresponds to
* [`ScrVersType`](https://github.com/sillsdev/libpalaso/blob/master/SIL.Scripture/Versification.cs#L1340),
* but this is not correct and full design.
*/
'platformScripture.versification': number;
/**
* Which books are present in this Scripture project. Represented as a string with 0 or 1 for
* each possible book by [standardized book
* code](https://github.com/sillsdev/libpalaso/blob/master/SIL.Scripture/Canon.cs#L226) (123
* characters long)
*
* @example
* '100111000000000000110000001000000000010111111111111111111111111111000000000000000000000000000000000000000000100000000000000'
*/
'platformScripture.booksPresent': string;
}
}
22 changes: 0 additions & 22 deletions extensions/src/usfm-data-provider/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,26 +378,4 @@ declare module 'papi-shared-types' {
export interface DataProviders {
usfm: UsfmDataProvider;
}

export interface ProjectSettingTypes {
/**
* Which versification scheme this Scripture project uses
*
* WARNING: This setting is an example and needs to be updated to support proper versification
* specification! For the moment, it simply corresponds to
* [`ScrVersType`](https://github.com/sillsdev/libpalaso/blob/master/SIL.Scripture/Versification.cs#L1340),
* but this is not correct and full design.
*/
'platformScripture.versification': number;
/**
* Which books are present in this Scripture project. Represented as a string with 0 or 1 for
* each possible book by [standardized book
* code](https://github.com/sillsdev/libpalaso/blob/master/SIL.Scripture/Canon.cs#L226) (123
* characters long)
*
* @example
* '100111000000000000110000001000000000010111111111111111111111111111000000000000000000000000000000000000000000100000000000000'
*/
'platformScripture.booksPresent': string;
}
}
37 changes: 9 additions & 28 deletions src/extension-host/data/core-project-settings-info.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,22 @@ export const platformProjectSettings: ProjectSettingsContribution = {
label: '%project_settings_platform_language_label%',
default: '%project_language_missing%',
},
'platformScripture.booksPresent': {
label: '%project_settings_platform_booksPresent_label%',
description: '%project_settings_platform_booksPresent_description%',
default:
// 1
// 1 2 3 4 5 6 7 8 9 0 1 2 3
// 34567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
},
'platformScripture.versification': {
label: '%project_settings_platformScripture_versification_label%',
description: '%project_settings_platformScripture_versification_description%',
default: 4,
},
},
};

// Based on https://github.com/paranext/paranext-core/blob/5c403e272b002ddd8970f735bc119f335c78c509/extensions/src/usfm-data-provider/index.d.ts#L401
// Should be 123 characters long
const booksPresentSettingsValidator: ProjectSettingValidator<
'platformScripture.booksPresent'
> = async (newValue: string): Promise<boolean> => {
return newValue.length === 123 && newValue.replace(/[01]/g, '').length === 0;
const fullNameValidator: ProjectSettingValidator<'platform.fullName'> = async (newValue) => {
return typeof newValue === 'string';
};

// Based on https://github.com/paranext/paranext-core/blob/5c403e272b002ddd8970f735bc119f335c78c509/extensions/src/usfm-data-provider/index.d.ts#L391
// There are 7 options in the enum
const versificationSettingsValidator: ProjectSettingValidator<
'platformScripture.versification'
> = async (newValue: number): Promise<boolean> => {
return typeof newValue === 'number' && newValue >= 0 && newValue <= 6;
// TODO: Validate that strings in the array to match BCP 47 values once the i18n code is ready
const languageValidator: ProjectSettingValidator<'platform.language'> = async (
newValue: string,
): Promise<boolean> => {
return typeof newValue === 'string';
};

/** Info about all settings built into core. Does not contain info for extensions' settings */
export const coreProjectSettingsValidators: Partial<AllProjectSettingsValidators> = {
'platformScripture.booksPresent': booksPresentSettingsValidator,
'platformScripture.versification': versificationSettingsValidator,
'platform.fullName': fullNameValidator,
'platform.language': languageValidator,
};
2 changes: 1 addition & 1 deletion src/extension-host/data/core-settings-info.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const verseRefSettingsValidator: SettingValidator<'platform.verseRef'> =
};

// TODO: Validate that strings in the array to match BCP 47 values once the i18n code is ready
export const interfaceLanguageValidator: SettingValidator<'platform.interfaceLanguage'> = async (
const interfaceLanguageValidator: SettingValidator<'platform.interfaceLanguage'> = async (
newValue: string[],
): Promise<boolean> => {
return (
Expand Down

0 comments on commit f106a34

Please sign in to comment.