Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
batosai committed Jan 24, 2024
2 parents 90272e7 + ab48c02 commit bc29712
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 68 deletions.
22 changes: 2 additions & 20 deletions fractal.helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ const flashMessages = {
}
}

const defaultT = key => {
const sample = {
'user.name': 'Nom',
'page.title': 'Titre',
}

return sample[key] ? sample[key] : key
}

const defaultFlash = {
values:null,
has: name => name ? false : false,
Expand Down Expand Up @@ -67,16 +58,8 @@ const jrmc = {

return option.selected ?? false
},
getLabel: (props, context = { translator: { prefix: '', t: (k) => k } }) => {
const t = context.translator.t

let name = props.has('name') ? props.get('name') : ''

if (props.has('translator.prefix')) {
name = t(`${props.translator.prefix}${name}`)
} else if (context.translator.prefix) {
name = t(`${context.translator.prefix}${name}`)
}
getLabel: props => {
const name = props.has('name') ? props.get('name') : ''

return `${string.capitalCase(string.noCase(name))}:`
},
Expand Down Expand Up @@ -125,5 +108,4 @@ module.exports = {
}
},
flashMessages,
t: defaultT
}
13 changes: 0 additions & 13 deletions fractal/components/03-form/03-form-translate-labels.edge

This file was deleted.

22 changes: 1 addition & 21 deletions fractal/components/03-form/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,4 @@
| method | GET/POST | HTTP method (default POST) |
| csrf | true/false | add csrf input hidden (default true) |
| error | true/false | show errors message (default true) |
| translator | object | config for translate |
| translator.prefix | property | prefix translator |
| translator.t | property | function translate |

## Translator AdonisJS

```
{
prefix: 'user.',
t: (key) => t(key)
}
@jrmc.form({ translator: { prefix: 'user.', t: (key) => t(key) }})
@jrmc.form.control({ name: 'name' })
@!jrmc.form.input({ class: 'input-bordered' })
@end
@end
=> exec i18n helper Adonis t('user.name')
```
| object | object model | entity model for default value |
4 changes: 4 additions & 0 deletions fractal/docs/03-changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.8.0

- Remove label translator, this was a bad idea. It is preferable and cleaner to use the label attribute of the control component

# 1.7.0

- Form label translator
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jrmc/edge-components",
"version": "1.7.1",
"version": "1.8.0beta",
"description": "",
"main": "build/index.js",
"repository": {
Expand Down
12 changes: 2 additions & 10 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,8 @@ const obj = {

return option.selected ?? false
},
getLabel: (props, context = { translator: { prefix: '', t: (k) => k } }) => {
const t = context.translator.t

let name = props.has('name') ? props.get('name') : ''

if (props.has('translator.prefix')) {
name = t(`${props.translator.prefix}${name}`)
} else if (context?.translator?.prefix) {
name = t(`${context.translator.prefix}${name}`)
}
getLabel: (props) => {
const name = props.has('name') ? props.get('name') : ''

return `${string.capitalCase(string.noCase(name))}:`
},
Expand Down
3 changes: 1 addition & 2 deletions views/components/form.edge
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
@inject({
object: $props.get('object'),
translator: $props.has('translator') ? $props.get('translator') : { prefix: '', t: (k) => k }
})

<form method="{{ jrmc.getMethodForm($props, 'POST') }}" {{ $props.serializeExcept(['method', 'object', 'translator']) }}>
<form method="{{ jrmc.getMethodForm($props, 'POST') }}" {{ $props.serializeExcept(['method', 'object']) }}>

@if(csrfField && $props.get('csrf') !== false)~
{{ csrfField() }}
Expand Down
2 changes: 1 addition & 1 deletion views/components/form/control.edge
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@!jrmc.form.label({ text: $props.get('label'), class: 'cursor-pointer', for: jrmc.getId($props), required: jrmc.getRequired($props), })
@end~
@elseif($props.has('name'))~
@!jrmc.form.label({ text: jrmc.getLabel($props, $context), class: 'cursor-pointer', for: jrmc.getId($props), required: jrmc.getRequired($props), })
@!jrmc.form.label({ text: jrmc.getLabel($props), class: 'cursor-pointer', for: jrmc.getId($props), required: jrmc.getRequired($props), })
@end~

{{{ await $slots.main() || '' }}}
Expand Down

0 comments on commit bc29712

Please sign in to comment.