Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IRMA
Github mirrors
irmago
Commits
58b74cb1
Commit
58b74cb1
authored
Sep 18, 2017
by
Sietse Ringers
Browse files
Simplify TranslatedString
parent
66ea0b31
Changes
2
Hide whitespace changes
Inline
Side-by-side
descriptions.go
View file @
58b74cb1
...
...
@@ -82,23 +82,29 @@ func (ct CredentialType) IndexOf(ai AttributeTypeIdentifier) (int, error) {
return
-
1
,
errors
.
New
(
"Attribute identifier not found"
)
}
// TranslatedString represents an XML tag containing a string translated to multiple languages.
// For example: <Foo id="bla"><en>Hello world</en><nl>Hallo wereld</nl></Foo>
type
TranslatedString
struct
{
Translations
[]
struct
{
XMLName
xml
.
Name
Text
string
`xml:",chardata"`
}
`xml:",any"`
}
// Translation returns the specified translation.
func
(
ts
*
TranslatedString
)
Translation
(
lang
string
)
string
{
for
_
,
translation
:=
range
ts
.
Translations
{
if
translation
.
XMLName
.
Local
==
lang
{
return
translation
.
Text
}
// TranslatedString is a map of translated strings.
type
TranslatedString
map
[
string
]
string
// UnmarshalXML unmarshals an XML tag containing a string translated to multiple languages,
// for example: <Foo><en>Hello world</en><nl>Hallo wereld</nl></Foo>
// into a TranslatedString: { "en": "Hello world" , "nl": "Hallo wereld" }
func
(
ts
*
TranslatedString
)
UnmarshalXML
(
d
*
xml
.
Decoder
,
start
xml
.
StartElement
)
error
{
if
map
[
string
]
string
(
*
ts
)
==
nil
{
*
ts
=
TranslatedString
(
make
(
map
[
string
]
string
))
}
temp
:=
&
struct
{
Translations
[]
struct
{
XMLName
xml
.
Name
Text
string
`xml:",chardata"`
}
`xml:",any"`
}{}
if
err
:=
d
.
DecodeElement
(
temp
,
&
start
);
err
!=
nil
{
return
err
}
for
_
,
translation
:=
range
temp
.
Translations
{
(
*
ts
)[
translation
.
XMLName
.
Local
]
=
translation
.
Text
}
return
""
return
nil
}
// Identifier returns the identifier of the specified credential type.
...
...
irmago_test.go
View file @
58b74cb1
...
...
@@ -132,15 +132,15 @@ func TestParseStore(t *testing.T) {
assert
.
NotNil
(
t
,
MetaStore
.
Issuers
[
NewIssuerIdentifier
(
"irma-demo.RU"
)]
.
CurrentPublicKey
()
.
N
,
"irma-demo.RU public key has no modulus"
)
assert
.
Equal
(
t
,
"Irma Demo"
,
MetaStore
.
SchemeManagers
[
NewSchemeManagerIdentifier
(
"irma-demo"
)]
.
Name
.
Translation
(
"en"
)
,
MetaStore
.
SchemeManagers
[
NewSchemeManagerIdentifier
(
"irma-demo"
)]
.
Name
[
"en"
]
,
"irma-demo scheme manager has unexpected name"
)
assert
.
Equal
(
t
,
"Radboud Universiteit Nijmegen"
,
MetaStore
.
Issuers
[
NewIssuerIdentifier
(
"irma-demo.RU"
)]
.
Name
.
Translation
(
"en"
)
,
MetaStore
.
Issuers
[
NewIssuerIdentifier
(
"irma-demo.RU"
)]
.
Name
[
"en"
]
,
"irma-demo.RU issuer has unexpected name"
)
assert
.
Equal
(
t
,
"Student Card"
,
MetaStore
.
Credentials
[
NewCredentialTypeIdentifier
(
"irma-demo.RU.studentCard"
)]
.
ShortName
.
Translation
(
"en"
)
,
MetaStore
.
Credentials
[
NewCredentialTypeIdentifier
(
"irma-demo.RU.studentCard"
)]
.
ShortName
[
"en"
]
,
"irma-demo.RU.studentCard has unexpected name"
)
assert
.
Equal
(
t
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment