Skip to content

Commit

Permalink
translate definition file in english
Browse files Browse the repository at this point in the history
add a test to make sure labels are consistent in both fr and en files, fix some issues in both definition files

closes #1135
  • Loading branch information
kaligrafy committed Dec 16, 2024
1 parent 3108593 commit a06dd46
Show file tree
Hide file tree
Showing 5 changed files with 572 additions and 529 deletions.
4 changes: 3 additions & 1 deletion packages/chaire-lib-backend/src/config/server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ export const setProjectConfiguration = (newConfig: Partial<ProjectConfiguration<
engines: {
osrmRouting: {
port: osrmModesInDeprecatedFormat[osrmMode].port,
host: osrmModesInDeprecatedFormat[osrmMode].host || osrmModesInDeprecatedFormat[osrmMode].osrmPath,
host:
osrmModesInDeprecatedFormat[osrmMode].host ||
osrmModesInDeprecatedFormat[osrmMode].osrmPath,
autoStart: osrmModesInDeprecatedFormat[osrmMode].autoStart,
enabled: osrmModesInDeprecatedFormat[osrmMode].enabled
}
Expand Down
83 changes: 83 additions & 0 deletions packages/transition-backend/file/__tests__/definitions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import fs from 'fs';
describe('LaTeX Label Consistency Tests', () => {
// Helper function to extract labels from LaTeX content
function extractLabels(content) {
const labelRegex = /\\label{([^}]+)}/g;
const labels = new Set();
let match;

while ((match = labelRegex.exec(content)) !== null) {
labels.add(match[1]);
}

return labels;
}

// Read both files before all tests
let enContent;
let frContent;
let enLabels;
let frLabels;

beforeAll(() => {
enContent = fs.readFileSync('file/definitions/definitions-en.tex', 'utf8');
frContent = fs.readFileSync('file/definitions/definitions-fr.tex', 'utf8');
enLabels = extractLabels(enContent);
frLabels = extractLabels(frContent);
});

test('all English labels exist in French file', () => {
const missingInFr = [...enLabels].filter((label) => !frLabels.has(label));
expect(missingInFr).toEqual([]);
});

test('all French labels exist in English file', () => {
const missingInEn = [...frLabels].filter((label) => !enLabels.has(label));
expect(missingInEn).toEqual([]);
});

test('both files have the same number of labels', () => {
expect(enLabels.size).toBe(frLabels.size);
});

test('labels appear in the same order in both files', () => {
const enLabelArray = [...enLabels];
const frLabelArray = [...frLabels];

expect(enLabelArray).toEqual(frLabelArray);
});

test('no duplicate labels in English file', () => {
const duplicates = new Set();
const seen = new Set();
const labelRegex = /\\label{([^}]+)}/g;
let match;

while ((match = labelRegex.exec(enContent)) !== null) {
const label = match[1];
if (seen.has(label)) {
duplicates.add(label);
}
seen.add(label);
}

expect([...duplicates]).toEqual([]);
});

test('no duplicate labels in French file', () => {
const duplicates = new Set();
const seen = new Set();
const labelRegex = /\\label{([^}]+)}/g;
let match;

while ((match = labelRegex.exec(frContent)) !== null) {
const label = match[1];
if (seen.has(label)) {
duplicates.add(label);
}
seen.add(label);
}

expect([...duplicates]).toEqual([]);
});
});
2 changes: 2 additions & 0 deletions packages/transition-backend/file/definitions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ When adding or modifying information on these files, they must follow the alread
\makecell[r]{Title} & \[Symbol\] & \[Unit\] & \[Expression\] & Description \\
\hline
```
After any edit, make sure labels are consistent in both files. For this, run `yarn workspace transition-backend test definitions`.

Each row is starts with a label that allows for it to be located by the tooltip component and ends with `\hline`. Each cell is separated with `&`, and starts and ends with a space. The unit and expression can be empty, in which case they must be represented by a single hyphen (`-`). The symbol, unit, and expression are mathematical expressions, and must be start `\[` and end with `\]`, unless they are empty. Finally, any change must be translated and added to both the French and English file.
Loading

0 comments on commit a06dd46

Please sign in to comment.