Skip to content

Commit

Permalink
Merge pull request #102 from ONSdigital/apply-welsh-to-version-9-who-…
Browse files Browse the repository at this point in the history
…lives-here

Apply welsh to version 9 who lives here
  • Loading branch information
saedwards authored Nov 23, 2018
2 parents 8c780bb + 8088ab0 commit e25de11
Show file tree
Hide file tree
Showing 51 changed files with 8,688 additions and 3 deletions.
3 changes: 1 addition & 2 deletions _includes/header-eq-default.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
{{ site.title }}
{% endif %}
</span>
<button class="btn btn--ghost u-fr">Save and
complete later</button>
<button class="btn btn--ghost u-fr">Cadw a chwblhau'n ddiweddarach</button>
</h1>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions _js/standard-bundle.js.tmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// import './modules/details-toggle';
import './modules/domready';
import './modules/focus-styles';
import './modules/inpagelink';
144 changes: 144 additions & 0 deletions _prototypes/your-household-v9-cy/assets/household.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import {autoIncrementId} from './utils';

export const HOUSEHOLD_MEMBERS_STORAGE_KEY = 'household-members';
export const USER_HOUSEHOLD_MEMBER_ID = 'person_me';
export const HOUSEHOLD_MEMBER_TYPE = 'household-member';
export const VISITOR_TYPE = 'visitor';

/**
* Types
*/
export function person(opts) {
if (opts.firstName === '' || opts.lastName === '') {
console.log('Unable to create person with data: ',
opts.firstName,
!opts.middleName,
!opts.lastName);
}

let middleName = opts.middleName || '';

return {
fullName: opts.firstName + ' ' + middleName + ' ' + opts.lastName,
firstName: opts.firstName,
middleName,
lastName: opts.lastName
};
}

/**
* Storage
*/
export function getUserAsHouseholdMember() {
return getAllHouseholdMembers().find((member) => {
return member['@person'].id === USER_HOUSEHOLD_MEMBER_ID;
});
}

export function deleteUserAsHouseholdMember() {
deleteHouseholdMember(USER_HOUSEHOLD_MEMBER_ID);
}

export function deleteHouseholdMember(personId) {
let members = getAllHouseholdMembers().filter((member) => {
return member['@person'].id !== personId;
});

sessionStorage.setItem(HOUSEHOLD_MEMBERS_STORAGE_KEY,
JSON.stringify(members));
}

export function updateUserAsHouseholdMember(person, memberData) {
let userAsHouseholdMember = getUserAsHouseholdMember();

userAsHouseholdMember
? updateHouseholdMember(userAsHouseholdMember['@person'], memberData)
: addHouseholdMember(person, memberData, USER_HOUSEHOLD_MEMBER_ID);
}

export function updateHouseholdMember(person, memberData) {
let membersUpdated = getAllHouseholdMembers().map((member) => {
return member['@person'].id === person.id
? {...member, ...memberData, '@person': {...member['@person'], ...person}}
: member;
});

sessionStorage.setItem(HOUSEHOLD_MEMBERS_STORAGE_KEY,
JSON.stringify(membersUpdated));
}

export function addHouseholdMember(person, memberData, id) {
let people = getAllHouseholdMembers() || [];
memberData = memberData || {};

/**
* User is always first in the household list
*/
people[id === USER_HOUSEHOLD_MEMBER_ID ? 'unshift' : 'push']({
...memberData,
type: memberData.type || HOUSEHOLD_MEMBER_TYPE,
'@person': {
...person,
id: id || 'person' + autoIncrementId('household-members')
}
});

sessionStorage.setItem(HOUSEHOLD_MEMBERS_STORAGE_KEY, JSON.stringify(people));
}

export function getAllHouseholdMembers() {
return JSON.parse(sessionStorage.getItem(HOUSEHOLD_MEMBERS_STORAGE_KEY)) || [];
}

export function getHouseholdMemberByPersonId(id) {
return getAllHouseholdMembers().find(function(member) {
return member['@person'].id === id;
});
}

export function getMemberPersonId(member) {
return member['@person'].id;
}

/**
* Comparators
*/
export function isVisitor(member) {
return member.type === window.ONS.storage.KEYS.VISITOR_TYPE;
}

export function isHouseholdMember(member) {
return member.type === window.ONS.storage.KEYS.HOUSEHOLD_MEMBER_TYPE;
}

export function isOtherHouseholdMember(member) {
return member.type === window.ONS.storage.KEYS.HOUSEHOLD_MEMBER_TYPE &&
member['@person'].id !== window.ONS.storage.IDS.USER_HOUSEHOLD_MEMBER_ID;
}

export const tempAwayQuestionSentenceMap = {
'three-more': `Pobl sy'n byw y tu allan i'r Deyrnas Unedig fel arfer, ond sy'n
aros yn y Deyrnas Unedig am dri mis neu fwy`,
'perm-away': `Pobl sy'n gweithio oddi cartref yn y Deyrnas Unedig, os mai hwn
yw eu cartref parhaol neu gartref y teulu`,
'armed-forces': `Aelodau o'r lluoedd arfog, os mai hwn yw eu cartref parhaol
neu gartref y teulu`,
'less-twelve': `Pobl sydd y tu allan i’r Deyrnas Unedig dros dro am lai na 12
mis`,
'usually-temp': `Pobl sy'n aros dros dro, sy'n byw yn y Deyrnas Unedig fel
arfer, ond sydd heb gyfeiriad arall yn y Deyrnas Unedig, er enghraifft
perthnasau, ffrindiau`,
'other': `Pobl eraill sy’n byw yma fel arfer, gan gynnwys unrhyw un sydd oddi
cartref dros dro`
};

export const visitorQuestionSentenceMap = {
'usually-in-uk': `Pobl sydd fel arfer yn byw rywle arall yn y Deyrnas Unedig,
er enghraifft cariadon, ffrindiau neu berthnasau`,
'second-address': `Pobl sy'n aros yma gan mai dyma eu hail gyfeiriad, er
enghraifft, oherwydd gwaith. Mae eu cartref parhaol neu gartref y teulu
rywle arall`,
'less-three': `Pobl sy'n byw y tu allan i’r Deyrnas Unedig fel arfer, ond sy'n
aros yn y Deyrnas Unedig am lai na 3 mis`,
'on-holiday': 'Pobl sydd ar wyliau yma'
};
154 changes: 154 additions & 0 deletions _prototypes/your-household-v9-cy/assets/numbers-to-words.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/**
* Copied from:
* https://codereview.stackexchange.com/questions/90349/changing-number-to-words-in-javascript
* ===============
*/
var ONE_TO_NINETEEN = [
'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine', 'ten',
'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen',
'sixteen', 'seventeen', 'eighteen', 'nineteen'
];

var TENS = [
'ten', 'twenty', 'thirty', 'forty', 'fifty',
'sixty', 'seventy', 'eighty', 'ninety'
];

var SCALES = ['thousand', 'million', 'billion', 'trillion'];

// helper function for use with Array.filter
function isTruthy(item) {
return !!item;
}

// convert a number into 'chunks' of 0-999
function chunk(number) {
var thousands = [];

while(number > 0) {
thousands.push(number % 1000);
number = Math.floor(number / 1000);
}

return thousands;
}

// translate a number from 1-999 into English
function inEnglish(number) {
var thousands, hundreds, tens, ones, words = [];

if(number < 20) {
return ONE_TO_NINETEEN[number - 1]; // may be undefined
}

if(number < 100) {
ones = number % 10;
tens = number / 10 | 0; // equivalent to Math.floor(number / 10)

words.push(TENS[tens - 1]);
words.push(inEnglish(ones));

return words.filter(isTruthy).join('-');
}

hundreds = number / 100 | 0;
words.push(inEnglish(hundreds));
words.push('hundred');
words.push(inEnglish(number % 100));

return words.filter(isTruthy).join(' ');
}

// append the word for a scale. Made for use with Array.map
function appendScale(chunk, exp) {
var scale;
if (!chunk) {
return null;
}
scale = SCALES[exp - 1];
return [chunk, scale].filter(isTruthy).join(' ');
}

/**
* ===============
* End copy
*/

/**
* Modification - decorator
*/
var NUMBER_TO_POSITION_TEXT_MAP = {
'one': 'first',
'two': 'second',
'three': 'third',
'four': 'fourth',
'five': 'fifth',
'six': 'sixth',
'seven': 'seventh',
'eight': 'eighth',
'nine': 'ninth',
'ten': 'tenth',
'eleven': 'eleventh',
'twelve': 'twelfth',
'thirteen': 'thirteenth',
'fourteen': 'fourteenth',
'fifteen': 'fifteenth',
'sixteen': 'sixteenth',
'seventeen': 'seventeenth',
'eighteen': 'eighteenth',
'nineteen': 'nineteenth',

'twenty': 'twentieth',
'thirty': 'thirtieth',
'forty': 'fortieth',
'fifty': 'fiftieth',
'sixty': 'sixtieth',
'seventy': 'seventieth',
'eighty': 'eightieth',
'ninety': 'ninetieth',
'hundred': 'hundredth',

'thousand': 'thousandth',
'million': 'millionth',
'billion': 'billionth',
'trillion': 'trillionth'
};

export function numberToPositionWord(num) {
const str = chunk(num)
.map(inEnglish)
.map(appendScale)
.filter(isTruthy)
.reverse()
.join(' ');

const sub = str.split(' '),
lastWordDashSplitArr = sub[sub.length - 1].split('-'),
lastWord = lastWordDashSplitArr[lastWordDashSplitArr.length - 1],

newLastWord = (lastWordDashSplitArr.length > 1? lastWordDashSplitArr[0] + '-' : '') +
NUMBER_TO_POSITION_TEXT_MAP[lastWord];

/*console.log('str:', str);
console.log('sub:', sub);
console.log('lastWordDashSplitArr:', lastWordDashSplitArr);
console.log('lastWord:', lastWord);
console.log('newLastWord:', newLastWord);*/

const subCopy = [].concat(sub);
subCopy.pop();
const prefix = subCopy.join(' ');
const result = (prefix ? prefix + ' ' : '') + newLastWord;

// console.log('result', (prefix ? prefix + ' ' : '') + newLastWord);
return result;
}

export function numberToWordsStyleguide(number) {
if (number > 9) {
return number;
}

return ONE_TO_NINETEEN[number - 1];
}
Loading

0 comments on commit e25de11

Please sign in to comment.