Skip to content

Commit

Permalink
feat: translate names in exported CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
gakada committed Oct 1, 2019
1 parent 4990581 commit f4e5875
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions views/sidebar/export/build-csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ let _slotitems: any
let $slotitems: any
let $ships: any

const __ = i18next.getFixedT(null, ['poi-plugin-ship-info', 'resources'])
const __ = (s: string) =>
i18next.getFixedT(null, ['poi-plugin-ship-info', 'resources'])(s, {
keySeparator: 'chiba',
})

const getItemName = (index: number) => (ship: any) => {
const itemId = get(
_slotitems,
`${get(ship, `slot.${index}`)}.api_slotitem_id`,
)
return get($slotitems, `${itemId}.api_name`, 'NA')
return __(get($slotitems, `${itemId}.api_name`, 'NA'))
}

const getExItemName = (ship: any) => {
const itemId = get(_slotitems, `${get(ship, 'exslot')}.api_slotitem_id`)
return get($slotitems, `${itemId}.api_name`, 'NA')
return __(get($slotitems, `${itemId}.api_name`, 'NA'))
}

const buildConstFields = (key: string) => [
Expand Down Expand Up @@ -56,13 +59,18 @@ interface IFieldWithKey {
value: (ship: any) => string
}

const tlField = (key: string, f = (s: string) => s) => ({
key,
value: (ship: any) => __(f(ship[key])),
})

export const fields: Array<IFieldWithKey | string> = [
'id',
'name',
tlField('name'),
'yomi',
'fleetId',
'sallyArea',
'type',
tlField('type'),
'soku',
'lv',
'cond',
Expand Down Expand Up @@ -112,10 +120,7 @@ export const fields: Array<IFieldWithKey | string> = [
'losshp',
'repairtime',
'inDock',
{
key: 'after',
value: ship => get($ships, `${ship.after}.api_name`, 'NA'),
},
tlField('after', after => get($ships, `${after}.api_name`, 'NA')),
]

export const buildCsv = (rows: IShip[], sep = ',', end = '\n') => {
Expand Down

0 comments on commit f4e5875

Please sign in to comment.