Skip to content

Commit 3c1cf09

Browse files
committed
Refine translation config typing and usage for markdown and changelog generators
1 parent 6f248a0 commit 3c1cf09

File tree

6 files changed

+48
-65
lines changed

6 files changed

+48
-65
lines changed

README.md

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ create a documentation site that fits your needs, hosted in any static web hosti
2727
- [OpenApi](#openapi-1)
2828
- [Changelog](#changelog-1)
2929
- [🔬 Defining a configuration file](#-defining-a-configuration-file)
30-
- [🌐 Translation](#-translation-support)
30+
- [🌐 Translation](#-translation)
3131
- [⤵︎ Importing to your project](#︎-importing-to-your-project)
3232
- [📖 Documentation Guide](#-documentation-guide)
3333
- [📄 Generating OpenApi REST Definitions](#-generating-openapi-rest-definitions)
@@ -296,11 +296,9 @@ export default defineMarkdownConfig({
296296
targetDir: 'docs',
297297
scope: ['global', 'public'],
298298
translations: {
299-
markdown: {
300-
sections: {
301-
methods: 'Methods',
302-
properties: 'Properties',
303-
},
299+
sections: {
300+
methods: 'Methods',
301+
properties: 'Properties',
304302
},
305303
},
306304
...
@@ -633,8 +631,6 @@ This feature allows you to:
633631
- **Use custom business terminology** (e.g., "Business Operations" instead of "Methods")
634632
- **Partially override specific terms** while keeping the rest in English
635633

636-
Translation is supported for the `markdown` and `changelog` generators.
637-
638634
### How It Works
639635

640636
The translation system uses:
@@ -644,7 +640,8 @@ The translation system uses:
644640

645641
### Configuration
646642

647-
Add a `translations` property to your ApexDocs configuration (JS or TS file):
643+
Add a `translations` property to your ApexDocs configuration (JS or TS file) and pass
644+
the appropriate translation object, depending on the generator you're using:
648645

649646
```javascript
650647
import { defineMarkdownConfig } from '@cparra/apexdocs';
@@ -654,12 +651,10 @@ export default defineMarkdownConfig({
654651
targetDir: 'docs',
655652
scope: ['public', 'global'],
656653
translations: {
657-
markdown: {
658-
sections: {
659-
methods: 'Métodos',
660-
properties: 'Propiedades',
661-
fields: 'Campos',
662-
},
654+
sections: {
655+
methods: 'Métodos',
656+
properties: 'Propiedades',
657+
fields: 'Campos',
663658
},
664659
},
665660
});
@@ -673,35 +668,25 @@ For TypeScript projects, import the translation types for better autocomplete an
673668
import { defineMarkdownConfig } from '@cparra/apexdocs';
674669
import type { UserTranslations } from '@cparra/apexdocs';
675670

676-
const translations: UserTranslations = {
677-
markdown: {
678-
sections: {
679-
methods: 'Functions',
680-
},
671+
const markdownTranslations: UserTranslations['markdown'] = {
672+
sections: {
673+
methods: 'Functions',
681674
},
675+
// ...other translation keys as needed
682676
};
683677

684678
export default defineMarkdownConfig({
685679
sourceDir: 'src',
686680
targetDir: 'docs',
687681
scope: ['public', 'global'],
688-
translations,
682+
translations: markdownTranslations,
689683
});
690684
```
691685

692-
### Best Practices
693-
694-
1. **Start Small**: Begin with partial translations for the most important terms
695-
2. **Be Consistent**: Use the same terminology across your organization
696-
3. **Test Thoroughly**: Generate documentation with your translations to verify the output
697-
4. **Version Control**: Include your translation configurations in version control
698-
699686
### Notes
700687

701688
- Only the **markdown** and **changelog** generators support translations
702-
- The **OpenAPI** generator does not use the translation system
703689
- All translations are optional - anything not specified uses the English default
704-
- The system uses deep merging, so partial translations work seamlessly
705690

706691
For a complete example, see the [translation example](examples/translation/) in this repository.
707692

examples/translation/apexdocs.config.ts

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
import { defineMarkdownConfig, UserTranslations } from '../../src';
22

33
// Spanish translations
4-
const spanishTranslations: UserTranslations = {
5-
markdown: {
6-
sections: {
7-
methods: 'Métodos',
8-
properties: 'Propiedades',
9-
fields: 'Campos',
10-
constructors: 'Constructores',
11-
namespace: 'Espacio de Nombres',
12-
values: 'Valores',
13-
},
14-
details: {
15-
apiName: 'Nombre API',
16-
type: 'Tipo',
17-
signature: 'Firma',
18-
parameters: 'Parámetros',
19-
returnType: 'Tipo de Retorno',
20-
throws: 'Lanza',
21-
required: 'Requerido',
22-
author: 'Autor',
23-
},
24-
typeSuffixes: {
25-
class: 'Clase',
26-
interface: 'Interfaz',
27-
enum: 'Enum',
28-
trigger: 'Disparador',
29-
},
30-
inheritance: {
31-
inheritance: 'Herencia',
32-
implements: 'Implementa',
33-
},
4+
const spanishTranslations: UserTranslations['markdown'] = {
5+
sections: {
6+
methods: 'Métodos',
7+
properties: 'Propiedades',
8+
fields: 'Campos',
9+
constructors: 'Constructores',
10+
namespace: 'Espacio de Nombres',
11+
values: 'Valores',
12+
},
13+
details: {
14+
apiName: 'Nombre API',
15+
type: 'Tipo',
16+
signature: 'Firma',
17+
parameters: 'Parámetros',
18+
returnType: 'Tipo de Retorno',
19+
throws: 'Lanza',
20+
required: 'Requerido',
21+
author: 'Autor',
22+
},
23+
typeSuffixes: {
24+
class: 'Clase',
25+
interface: 'Interfaz',
26+
enum: 'Enum',
27+
trigger: 'Disparador',
28+
},
29+
inheritance: {
30+
inheritance: 'Herencia',
31+
implements: 'Implementa',
3432
},
3533
};
3634

src/core/changelog/generate-change-log.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function generateChangeLog(
3939
if (config.skipIfNoChanges && !hasChanges(changelog)) {
4040
return skip();
4141
}
42-
const translations = mergeTranslations(config.translations);
42+
const translations = mergeTranslations({ changelog: config.translations });
4343
return pipe(
4444
convertToRenderableChangelog(changelog, newManifest.types, translations),
4545
compile(translations),

src/core/markdown/adapters/renderable-to-page-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReferenceGuideReference, Renderable, RenderableBundle, RenderableEnum } from '../../renderables/types';
1+
import { ReferenceGuideReference, Renderable, RenderableBundle } from '../../renderables/types';
22
import { DocPageData, DocumentationBundle } from '../../shared/types';
33
import { pipe } from 'fp-ts/function';
44
import { CompilationRequest, Template } from '../../template';

src/core/markdown/generate-docs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export type MarkdownGeneratorConfig = Omit<
4949
};
5050

5151
export function generateDocs(unparsedBundles: UnparsedSourceBundle[], config: MarkdownGeneratorConfig) {
52-
const translations = mergeTranslations(config.translations);
52+
const translations = mergeTranslations({ markdown: config.translations });
5353
const convertToReferences = apply(parsedFilesToReferenceGuide, config);
5454
const convertToRenderableBundle = apply(parsedFilesToRenderableBundle, config);
5555
const convertToDocumentationBundleForTemplate = apply(

src/core/shared/types.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export type UserDefinedMarkdownConfig = {
4949
targetGenerator: 'markdown';
5050
excludeTags: string[];
5151
exclude: string[];
52-
translations?: UserTranslations;
52+
translations?: UserTranslations['markdown'];
5353
} & CliConfigurableMarkdownConfig &
5454
Partial<MarkdownConfigurableHooks>;
5555

@@ -76,7 +76,7 @@ export type UserDefinedChangelogConfig = {
7676
customObjectVisibility: string[];
7777
exclude: string[];
7878
skipIfNoChanges: boolean;
79-
translations?: UserTranslations;
79+
translations?: UserTranslations['changelog'];
8080
} & Partial<ChangelogConfigurableHooks>;
8181

8282
export type UserDefinedConfig = UserDefinedMarkdownConfig | UserDefinedOpenApiConfig | UserDefinedChangelogConfig;

0 commit comments

Comments
 (0)