i18n: fix enum values for Dossier.state
According to Rails i18n guide, enum values should be localized as `<model>/<enum>`, not as sub-values to the attribute. This fixes an exception in administrate when displaying a Dossier in the Manager. Note: we need to change the way GraphQL attributes are generated, because `AASM::Core::State#display_name` doesn’t honor the `model/attribute.value` convention (and instead tries to localize as `model.attribute/value`). So instead we lookup the localized name using ActiveRecord.
This commit is contained in:
parent
fb75f9d133
commit
b8f71bd52c
4 changed files with 14 additions and 18 deletions
|
@ -1088,7 +1088,7 @@ enum DossierState {
|
||||||
refuse
|
refuse
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Sans suite
|
Classé sans suite
|
||||||
"""
|
"""
|
||||||
sans_suite
|
sans_suite
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ module Types
|
||||||
class DossierType < Types::BaseObject
|
class DossierType < Types::BaseObject
|
||||||
class DossierState < Types::BaseEnum
|
class DossierState < Types::BaseEnum
|
||||||
Dossier.aasm.states.reject { |state| state.name == :brouillon }.each do |state|
|
Dossier.aasm.states.reject { |state| state.name == :brouillon }.each do |state|
|
||||||
value(state.name.to_s, state.display_name, value: state.name.to_s)
|
value(state.name.to_s, Dossier.human_attribute_name("state.#{state.name}"), value: state.name.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ module DossierHelper
|
||||||
|
|
||||||
def dossier_display_state(dossier_or_state, lower: false)
|
def dossier_display_state(dossier_or_state, lower: false)
|
||||||
state = dossier_or_state.is_a?(Dossier) ? dossier_or_state.state : dossier_or_state
|
state = dossier_or_state.is_a?(Dossier) ? dossier_or_state.state : dossier_or_state
|
||||||
display_state = I18n.t(state, scope: [:activerecord, :attributes, :dossier, :state])
|
display_state = Dossier.human_attribute_name("state.#{state}")
|
||||||
lower ? display_state.downcase : display_state
|
lower ? display_state.downcase : display_state
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,20 +9,16 @@ fr:
|
||||||
montant_projet: 'Le montant du projet'
|
montant_projet: 'Le montant du projet'
|
||||||
montant_aide_demande: "Le montant d’aide demandée"
|
montant_aide_demande: "Le montant d’aide demandée"
|
||||||
date_previsionnelle: "La date de début prévisionnelle"
|
date_previsionnelle: "La date de début prévisionnelle"
|
||||||
state: &state
|
state: "État"
|
||||||
brouillon: "Brouillon"
|
|
||||||
en_construction: "En construction"
|
|
||||||
en_instruction: "En instruction"
|
|
||||||
accepte: "Accepté"
|
|
||||||
refuse: "Refusé"
|
|
||||||
sans_suite: "Classé sans suite"
|
|
||||||
autorisation_donnees: Acceptation des CGU
|
autorisation_donnees: Acceptation des CGU
|
||||||
state/brouillon: Brouillon
|
dossier/state: &state
|
||||||
state/en_construction: En construction
|
brouillon: "Brouillon"
|
||||||
state/en_instruction: En instruction
|
en_construction: "En construction"
|
||||||
state/accepte: Accepté
|
en_instruction: "En instruction"
|
||||||
state/refuse: Refusé
|
accepte: "Accepté"
|
||||||
state/sans_suite: Sans suite
|
refuse: "Refusé"
|
||||||
|
sans_suite: "Classé sans suite"
|
||||||
traitement:
|
traitement:
|
||||||
state:
|
state: "État"
|
||||||
<<: *state
|
traitement/state:
|
||||||
|
<<: *state
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue