Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add finnish translations #49

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import en from './locales/en'

import es from './locales/es'

import fi from './locales/fi'

import fr from './locales/fr'

import he from './locales/he'
Expand Down Expand Up @@ -58,4 +60,4 @@ import zh from './locales/zh'
/**
* ✏️ Then add it to the list here:
*/
export { ar, ca, cs, da, de, en, es, fr, he, hu, it, ja, ko, nb, nl, lt, ru, pl, pt, sk, sr, sv, th, tr, vi, zh }
export { ar, ca, cs, da, de, en, es, fi, fr, he, hu, it, ja, ko, nb, nl, lt, ru, pl, pt, sk, sr, sv, th, tr, vi, zh }
233 changes: 233 additions & 0 deletions src/locales/fi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
/**
* Here we can import additional helper functions to assist in formatting our
* language. Feel free to add additional helper methods to libs/formats if it
* assists in creating good validation messages for your locale.
*/
import { sentence as s } from '../libs/formats'

/**
* This is the ISO 639-1 and (optionally) ISO 639-2 language "tag".
* Some valid examples:
* zh
* zh-CN
* zh-HK
* en
* en-GB
*/
const locale = 'fi'

/**
* This is an object of functions that each produce valid responses. There's no
* need for these to be 1-1 with english, feel free to change the wording or
* use/not use any of the variables available in the object or the
* arguments for the message to make the most sense in your language and culture.
*
* The validation context object includes the following properties:
* {
* args // Array of rule arguments: between:5,10 (args are ['5', '10'])
* name: // The validation name to be used
* value: // The value of the field (do not mutate!),
* vm: the // FormulateInput instance this belongs to,
* formValues: // If wrapped in a FormulateForm, the value of other form fields.
* }
*/
const localizedValidationMessages = {

/**
* Valid accepted value.
*/
accepted: function ({ name }) {
return `Hyväksy ${name}.`
},

/**
* The date is not after.
*/
after: function ({ name, args }) {
if (Array.isArray(args) && args.length) {
return `${s(name)} kenttä tulee olla ajankohdan ${args[0]} jälkeen.`
}
return `${s(name)} tulee olla myöhäisempi ajankohta.`
},

/**
* The value is not a letter.
*/
alpha: function ({ name }) {
return `${s(name)} kenttä voi sisältää vain kirjaimia.`
},

/**
* Rule: checks if the value is alpha numeric
*/
alphanumeric: function ({ name }) {
return `${s(name)} kenttä voi sisältää vain kirjaimia tai numeroita.`
},

/**
* The date is not before.
*/
before: function ({ name, args }) {
if (Array.isArray(args) && args.length) {
return `${s(name)} kenttä tulee olla ajankohdan ${args[0]} jälkeen.`
}
return `${s(name)} tulee olla aikaisempi ajankohta.`
},

/**
* The value is not between two numbers or lengths
*/
between: function ({ name, value, args }) {
const force = Array.isArray(args) && args[2] ? args[2] : false
if ((!isNaN(value) && force !== 'length') || force === 'value') {
return `${s(name)} kentän arvo tulee olla ${args[0]} ja ${args[1]} väliltä.`
}
return `${s(name)} kentän arvon pituus tulee olla ${args[0]} ja ${args[1]} väliltä.`
},

/**
* The confirmation field does not match
*/
confirm: function ({ name, args }) {
return `${s(name)} kenttä ei täsmää.`
},

/**
* Is not a valid date.
*/
date: function ({ name, args }) {
if (Array.isArray(args) && args.length) {
return `${s(name)} on virheellinen päivämäärä, käytä seuraavaa formaattia ${args[0]}`
}
return `${s(name)} on virheellinen päivämäärä.`
},

/**
* The default render method for error messages.
*/
default: function ({ name }) {
return `Kenttä on virheellinen.`
},

/**
* Is not a valid email address.
*/
email: function ({ name, value }) {
if (!value) {
return 'Kirjoita sähköpostiosoite.'
}
return `“${value}” on virheellinen sähköposti.`
},

/**
* Ends with specified value
*/
endsWith: function ({ name, value }) {
if (!value) {
return `Tämä kenttä päättyy virheellisellä arvolla.`
}
return `“${value}” arvo päättyy virheellisesti.`
},

/**
* Value is an allowed value.
*/
in: function ({ name, value }) {
if (typeof value === 'string' && value) {
return `“${s(value)}” arvo ei ole sallittu arvo kentälle ${name}.`
}
return `Tämä ei ole sallittu arvo kentälle ${name}.`
},

/**
* Value is not a match.
*/
matches: function ({ name }) {
return `${s(name)} kentän arvo ei ole sallittu.`
},

/**
* The maximum value allowed.
*/
max: function ({ name, value, args }) {
if (Array.isArray(value)) {
return `Kentän ${name} valintojen määrän tulisi olla enintään ${args[0]}.`
}
const force = Array.isArray(args) && args[1] ? args[1] : false
if ((!isNaN(value) && force !== 'length') || force === 'value') {
return `${s(name)} kentän arvo tulee olla pienempi tai yhtä pieni kuin ${args[0]}.`
}
return `${s(name)} kentän arvo tulee olla enintään ${args[0]} merkkiä pitkä.`
},

/**
* The (field-level) error message for mime errors.
*/
mime: function ({ name, args }) {
return `${s(name)} kenttä tulee olla tyyppiä: ${args[0] || 'Ei sallittuja tiedostomuotoja asetettu.'}`
},

/**
* The maximum value allowed.
*/
min: function ({ name, value, args }) {
if (Array.isArray(value)) {
return `Kentän ${name} valintojen määrän tulisi olla vähintään ${args[0]}.`
}
const force = Array.isArray(args) && args[1] ? args[1] : false
if ((!isNaN(value) && force !== 'length') || force === 'value') {
return `${s(name)} kentän arvo tulee olla vähintään ${args[0]}.`
}
return `${s(name)} kentän arvo tulee olla vähintään ${args[0]} merkkiä pitkä.`
},

/**
* The field is not an allowed value
*/
not: function ({ name, value }) {
return `“${value}” ei ole sallittu arvo kentälle ${name}.`
},

/**
* The field is not a number
*/
number: function ({ name }) {
return `Kenttä ${s(name)} tulee olla numero.`
},

/**
* Required field.
*/
required: function ({ name }) {
return `Kenttä ${s(name)} on pakollinen.`
},

/**
* Starts with specified value
*/
startsWith: function ({ name, value }) {
if (!value) {
return `Tämä kenttä ei ala oikealla arvolla.`
}
return `Arvo “${value}” ei ala sallitusti.`
},

/**
* Value is not a url.
*/
url: function ({ name }) {
return `Anna oikea URL-osoite.`
}
}

/**
* This creates a vue-formulate plugin that can be imported and used on each
* project.
*/
export default function (instance) {
instance.extend({
locales: {
[locale]: localizedValidationMessages
}
})
}
26 changes: 26 additions & 0 deletions test/unit/fi.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as locales from '@/locales'

// ✏️ Edit these to be the localized language
const locale = 'fi'

// ✏️ Edit your locale's name
describe('Finnish translation', () => {
it('exports a function', () => {
expect(typeof locales[locale]).toBe('function')
})

it('calls extend on the formulate instance', () => {
const instance = { extend: jest.fn() }
locales[locale](instance)
expect(instance.extend.mock.calls.length).toBe(1)
})

it('includes all the validation results that english does', () => {
const instance = { extend: jest.fn() }
locales.en(instance)
locales[locale](instance)
const englishMessages = Object.keys(instance.extend.mock.calls[0][0].locales.en)
const localizedMessages = Object.keys(instance.extend.mock.calls[1][0].locales[locale])
expect(englishMessages).toEqual(localizedMessages)
})
})