Skip to content

Commit

Permalink
Translation tempaltes: Allow specifying comments
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator committed Sep 21, 2023
1 parent aeab495 commit 2dbea52
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 9 deletions.
50 changes: 48 additions & 2 deletions .github/ISSUE_TEMPLATE/translation-js-draw-de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ body:
label: "dragAndDropHereOrBrowse"
description: "Translate `Drag and drop here
or
{{browse}}`."
{{browse}}`.
> **Note**:
> Uses {{curly braces}} to denote bold text"
placeholder: "Drag and drop here
or
{{browse}}"
Expand Down Expand Up @@ -205,6 +208,22 @@ or
value: "Auswahl duplizieren"
validations:
required: false
- type: input
id: translation-exit
attributes:
label: "exit"
description: "Translate `Exit`."
placeholder: "Exit"
validations:
required: false
- type: input
id: translation-save
attributes:
label: "save"
description: "Translate `Save`."
placeholder: "Save"
validations:
required: false
- type: input
id: translation-undo
attributes:
Expand Down Expand Up @@ -320,6 +339,14 @@ or
value: "Gitter: "
validations:
required: false
- type: input
id: translation-enableAutoresizeOption
attributes:
label: "enableAutoresizeOption"
description: "Translate `Auto-resize`."
placeholder: "Auto-resize"
validations:
required: false
- type: input
id: translation-toggleOverflow
attributes:
Expand Down Expand Up @@ -438,7 +465,10 @@ or
id: translation-closeSidebar
attributes:
label: "closeSidebar"
description: "Translate ``(toolName) => `Close sidebar for ${toolName}` ``."
description: "Translate ``(toolName) => `Close sidebar for ${toolName}` ``.
> **Note**:
> Currently used as an accessibilty label"
placeholder: "(toolName) => `Close sidebar for ${toolName}`"
value: "(toolName) => `Close sidebar for ${toolName}`"
validations:
Expand Down Expand Up @@ -792,6 +822,22 @@ or
value: "(newSize) => `Bildgröße auf ${newSize.w}x${newSize.h} geändert`"
validations:
required: false
- type: input
id: translation-enabledAutoresizeOutputCommand
attributes:
label: "enabledAutoresizeOutputCommand"
description: "Translate `Enabled output autoresize`."
placeholder: "Enabled output autoresize"
validations:
required: false
- type: input
id: translation-disabledAutoresizeOutputCommand
attributes:
label: "disabledAutoresizeOutputCommand"
description: "Translate `Disabled output autoresize`."
placeholder: "Disabled output autoresize"
validations:
required: false
- type: input
id: translation-addElementAction
attributes:
Expand Down
50 changes: 48 additions & 2 deletions .github/ISSUE_TEMPLATE/translation-js-draw-es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ body:
label: "dragAndDropHereOrBrowse"
description: "Translate `Drag and drop here
or
{{browse}}`."
{{browse}}`.
> **Note**:
> Uses {{curly braces}} to denote bold text"
placeholder: "Drag and drop here
or
{{browse}}"
Expand Down Expand Up @@ -198,6 +201,22 @@ or
value: "Duplica la selección"
validations:
required: false
- type: input
id: translation-exit
attributes:
label: "exit"
description: "Translate `Exit`."
placeholder: "Exit"
validations:
required: false
- type: input
id: translation-save
attributes:
label: "save"
description: "Translate `Save`."
placeholder: "Save"
validations:
required: false
- type: input
id: translation-undo
attributes:
Expand Down Expand Up @@ -311,6 +330,14 @@ or
placeholder: "Grid"
validations:
required: false
- type: input
id: translation-enableAutoresizeOption
attributes:
label: "enableAutoresizeOption"
description: "Translate `Auto-resize`."
placeholder: "Auto-resize"
validations:
required: false
- type: input
id: translation-toggleOverflow
attributes:
Expand Down Expand Up @@ -427,7 +454,10 @@ or
id: translation-closeSidebar
attributes:
label: "closeSidebar"
description: "Translate ``(toolName) => `Close sidebar for ${toolName}` ``."
description: "Translate ``(toolName) => `Close sidebar for ${toolName}` ``.
> **Note**:
> Currently used as an accessibilty label"
placeholder: "(toolName) => `Close sidebar for ${toolName}`"
value: "(toolName) => `Close sidebar for ${toolName}`"
validations:
Expand Down Expand Up @@ -773,6 +803,22 @@ or
value: "(newSize) => `Resized image to ${newSize.w}x${newSize.h}`"
validations:
required: false
- type: input
id: translation-enabledAutoresizeOutputCommand
attributes:
label: "enabledAutoresizeOutputCommand"
description: "Translate `Enabled output autoresize`."
placeholder: "Enabled output autoresize"
validations:
required: false
- type: input
id: translation-disabledAutoresizeOutputCommand
attributes:
label: "disabledAutoresizeOutputCommand"
description: "Translate `Disabled output autoresize`."
placeholder: "Disabled output autoresize"
validations:
required: false
- type: input
id: translation-addElementAction
attributes:
Expand Down
50 changes: 48 additions & 2 deletions .github/ISSUE_TEMPLATE/translation-js-draw-new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ body:
label: "dragAndDropHereOrBrowse"
description: "Translate `Drag and drop here
or
{{browse}}`."
{{browse}}`.
> **Note**:
> Uses {{curly braces}} to denote bold text"
placeholder: "Drag and drop here
or
{{browse}}"
Expand Down Expand Up @@ -185,6 +188,22 @@ or
placeholder: "Duplicate selection"
validations:
required: false
- type: input
id: translation-exit
attributes:
label: "exit"
description: "Translate `Exit`."
placeholder: "Exit"
validations:
required: false
- type: input
id: translation-save
attributes:
label: "save"
description: "Translate `Save`."
placeholder: "Save"
validations:
required: false
- type: input
id: translation-undo
attributes:
Expand Down Expand Up @@ -289,6 +308,14 @@ or
placeholder: "Grid"
validations:
required: false
- type: input
id: translation-enableAutoresizeOption
attributes:
label: "enableAutoresizeOption"
description: "Translate `Auto-resize`."
placeholder: "Auto-resize"
validations:
required: false
- type: input
id: translation-toggleOverflow
attributes:
Expand Down Expand Up @@ -397,7 +424,10 @@ or
id: translation-closeSidebar
attributes:
label: "closeSidebar"
description: "Translate ``(toolName) => `Close sidebar for ${toolName}` ``."
description: "Translate ``(toolName) => `Close sidebar for ${toolName}` ``.
> **Note**:
> Currently used as an accessibilty label"
placeholder: "(toolName) => `Close sidebar for ${toolName}`"
validations:
required: false
Expand Down Expand Up @@ -713,6 +743,22 @@ or
placeholder: "(newSize) => `Resized image to ${newSize.w}x${newSize.h}`"
validations:
required: false
- type: input
id: translation-enabledAutoresizeOutputCommand
attributes:
label: "enabledAutoresizeOutputCommand"
description: "Translate `Enabled output autoresize`."
placeholder: "Enabled output autoresize"
validations:
required: false
- type: input
id: translation-disabledAutoresizeOutputCommand
attributes:
label: "disabledAutoresizeOutputCommand"
description: "Translate `Disabled output autoresize`."
placeholder: "Disabled output autoresize"
validations:
required: false
- type: input
id: translation-addElementAction
attributes:
Expand Down
27 changes: 25 additions & 2 deletions packages/build-tool/src/buildTranslationTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ const generateTranslationTemplate = (
// Strings in the default locale (which has all strings translated)
defaultLocaleStrings: any,

// A map from translation keys to comments
translationComments?: Record<string, string|string[]>,

// The locale the user will be translating into
destLocale?: string,

// Strings in destLocale
destLocaleStrings?: any,
) => {
translationComments ??= {};

const bodyContentLines: string[] = [];

const addInput = (
Expand Down Expand Up @@ -110,9 +115,20 @@ const generateTranslationTemplate = (
currentTranslation = undefined;
}

let comments: string|string[] = translationComments[key] ?? [];
if (typeof comments === 'string') {
comments = [ comments ];
}
comments = comments.map(comment => `> **Note**:\n> ${comment.replace(/\n/g, '\n> ')}`);

const description = [
`Translate ${codeFormat(englishTranslation)}.`,
...comments,
].join('\n\n');

addInput('input', `translation-${key}`, {
label: `${key}`,
description: `Translate ${codeFormat(englishTranslation)}.`,
description,
placeholder: englishTranslation,
value: currentTranslation,
});
Expand Down Expand Up @@ -142,7 +158,11 @@ ${bodyContentLines.join('\n')}`;
const buildTranslationTemplate = async (source: TranslationSource, destFolder: string) => {
const projName = source.name;

const locales = (await import(source.path)).default;
// eslint-disable-next-line @typescript-eslint/no-var-requires
const translationData = require(source.path);

const locales = translationData.default ?? translationData.locales;
const comments = translationData.comments;

// Write the translation template for the current source.
// locale should be the destination locale or undefined if there is no specific
Expand All @@ -152,6 +172,9 @@ const buildTranslationTemplate = async (source: TranslationSource, destFolder: s
projName,
locales[source.defaultLocale],

// Comments on the translation keys
comments,

// Destination locale
locale,

Expand Down
12 changes: 12 additions & 0 deletions packages/js-draw/src/localizations/comments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

import { EditorLocalization } from '../localization';

/**
* Comments to help translators create translations.
*/
const comments: Partial<Record<keyof EditorLocalization, string>> = {
dragAndDropHereOrBrowse: 'Uses {{curly braces}} to denote bold text',
closeSidebar: 'Currently used as an accessibilty label',
};

export default comments;
10 changes: 9 additions & 1 deletion packages/js-draw/tools/allLocales.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

// eslint-disable-next-line @typescript-eslint/no-var-requires
const allLocales = require('../dist/cjs/localizations/getLocalizationTable').allLocales;
module.exports = allLocales;

// eslint-disable-next-line @typescript-eslint/no-var-requires
const comments = require('../dist/cjs/localizations/comments').default;


module.exports = {
locales: allLocales,
comments,
};

0 comments on commit 2dbea52

Please sign in to comment.