Commit dc1a952e authored by Alexander Turinske's avatar Alexander Turinske

Update cronstrue usage for internationalization

- use first entry of preferred locale to try to translate
  cronstrue output
- cronstrue defaults to en if language is not supported
parent 9c047683
import cronstrue from 'cronstrue';
import cronstrue from 'cronstrue/i18n';
import { convertToTitleCase, humanize } from '~/lib/utils/text_utility';
import { sprintf, s__, n__ } from '~/locale';
import { getPreferredLocales, sprintf, s__, n__ } from '~/locale';
import { NO_RULE_MESSAGE } from './constants';
const getActionText = (scanType) =>
......@@ -34,7 +34,9 @@ const humanizeBranches = (originalBranches) => {
};
const humanizeCadence = (cadence) => {
return cronstrue.toString(cadence, { verbose: true }).toLowerCase();
return cronstrue
.toString(cadence, { locale: getPreferredLocales()[0], verbose: true })
.toLowerCase();
};
const humanizePipelineRule = (rule) => {
......
......@@ -34,6 +34,11 @@ describe('humanizeActions', () => {
});
describe('humanizeRules', () => {
beforeEach(() => {
// Need to spy on window.navigator.languages as it is read-only
jest.spyOn(window.navigator, 'languages', 'get').mockReturnValueOnce(['en']);
});
it('returns the empty rules message in an Array if no rules are specified', () => {
expect(humanizeRules([])).toStrictEqual([NO_RULE_MESSAGE]);
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment