feat(i18n): url validation translations (#41190)

This commit is contained in:
Shaun Hamilton
2021-02-20 05:02:44 +00:00
committed by GitHub
parent b2ec1a3ef4
commit d70e33c1d2
4 changed files with 20 additions and 8 deletions

View File

@@ -1,18 +1,21 @@
import React from 'react';
import { Trans } from 'react-i18next';
// Matches editor links for: Repl.it, Glitch, CodeSandbox, GitHub
const editorRegex = /repl\.it\/(@|join\/)|glitch\.com\/edit\/#!|codesandbox\.io\/s\/|github\.com/;
const fCCRegex = /codepen\.io\/freecodecamp|freecodecamp\.rocks|github\.com\/freecodecamp/i;
const localhostRegex = /localhost:/;
export const editorValidator = value =>
editorRegex.test(value) ? 'Remember to submit the Live App URL.' : null;
editorRegex.test(value) ? <Trans>validation.editor-url</Trans> : null;
export const fCCValidator = value =>
fCCRegex.test(value) ? 'Remember to submit your own work.' : null;
fCCRegex.test(value) ? <Trans>validation.own-work-url</Trans> : null;
export const localhostValidator = value =>
localhostRegex.test(value)
? 'Remember to submit a publicly visible app URL.'
: null;
localhostRegex.test(value) ? (
<Trans>validation.publicly-visible-url</Trans>
) : null;
export const composeValidators = (...validators) => value =>
validators.reduce((error, validator) => error ?? validator?.(value), null);