2020-07-04 12:54:35 +02:00
|
|
|
/*
|
|
|
|
|
2022-04-25 09:53:55 +02:00
|
|
|
Package i18n provides translatable notification and error messages.
|
2020-07-04 12:54:35 +02:00
|
|
|
|
2022-04-13 22:17:59 +02:00
|
|
|
Copyright (c) 2018 - 2022 PhotoPrism UG. All rights reserved.
|
2020-07-04 12:54:35 +02:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
2022-02-21 15:30:18 +01:00
|
|
|
it under Version 3 of the GNU Affero General Public License (the "AGPL"):
|
|
|
|
<https://docs.photoprism.app/license/agpl>
|
2020-07-04 12:54:35 +02:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
2022-02-21 15:30:18 +01:00
|
|
|
The AGPL is supplemented by our Trademark and Brand Guidelines,
|
|
|
|
which describe how our Brand Assets may be used:
|
|
|
|
<https://photoprism.app/trademark>
|
2020-07-04 12:54:35 +02:00
|
|
|
|
2022-04-13 22:17:59 +02:00
|
|
|
Feel free to send an email to hello@photoprism.app if you have questions,
|
2020-07-04 12:54:35 +02:00
|
|
|
want to support our work, or just want to say hello.
|
|
|
|
|
|
|
|
Additional information can be found in our Developer Guide:
|
2022-02-27 17:32:54 +01:00
|
|
|
<https://docs.photoprism.app/developer-guide/>
|
2020-07-04 12:54:35 +02:00
|
|
|
|
|
|
|
*/
|
|
|
|
package i18n
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2020-07-15 01:26:54 +02:00
|
|
|
|
|
|
|
"github.com/leonelquinteros/gotext"
|
2020-07-04 12:54:35 +02:00
|
|
|
)
|
|
|
|
|
2020-07-15 01:26:54 +02:00
|
|
|
//go:generate xgettext --no-wrap --language=c --from-code=UTF-8 --output=../../assets/locales/messages.pot messages.go
|
|
|
|
|
2020-07-04 12:54:35 +02:00
|
|
|
type Message int
|
|
|
|
type MessageMap map[Message]string
|
|
|
|
|
2020-07-15 01:26:54 +02:00
|
|
|
func gettext(s string) string {
|
|
|
|
return gotext.Get(s)
|
2020-07-04 12:54:35 +02:00
|
|
|
}
|
|
|
|
|
2022-04-03 14:51:58 +02:00
|
|
|
// msgParams replaces message params with the actual values.
|
|
|
|
func msgParams(msg string, params ...interface{}) string {
|
2020-07-04 12:54:35 +02:00
|
|
|
if strings.Contains(msg, "%") {
|
|
|
|
msg = fmt.Sprintf(msg, params...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg
|
|
|
|
}
|
|
|
|
|
2022-04-03 14:51:58 +02:00
|
|
|
func Msg(id Message, params ...interface{}) string {
|
|
|
|
return msgParams(gotext.Get(Messages[id]), params...)
|
|
|
|
}
|
|
|
|
|
2020-07-04 12:54:35 +02:00
|
|
|
func Error(id Message, params ...interface{}) error {
|
2022-07-19 16:58:43 +02:00
|
|
|
return errors.New(Msg(id, params...))
|
2020-07-04 12:54:35 +02:00
|
|
|
}
|