-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
BOT_TOKEN= | ||
BOT_TOKEN= | ||
DEFAULT_LOCALE=uk | ||
BOT_PREFIX=🤖 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package messages | ||
|
||
import "fmt" | ||
|
||
type Helper struct { | ||
defaultLocale Locale | ||
botPrefix string | ||
} | ||
|
||
func NewMessagesHelper(defaultLocale, botPrefix string) (*Helper, error) { | ||
if !localeExist(Locale(defaultLocale)) { | ||
return nil, fmt.Errorf("default locale is not found among existing locales") | ||
} | ||
|
||
return &Helper{ | ||
defaultLocale: Locale(defaultLocale), | ||
botPrefix: botPrefix, | ||
}, nil | ||
} | ||
|
||
func (h *Helper) GetMessage(code Code, locale string) string { | ||
loc := Locale(locale) | ||
if !localeExist(loc) { | ||
loc = h.defaultLocale | ||
} | ||
|
||
return h.botPrefix + " " + fmt.Sprintf(LocalMessages[code][loc]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package messages | ||
|
||
type Locale string | ||
|
||
const ( | ||
LocaleUK Locale = "uk" | ||
LocaleEN Locale = "en" | ||
) | ||
|
||
func localeExist(locale Locale) bool { | ||
switch locale { | ||
case LocaleUK: | ||
return true | ||
case LocaleEN: | ||
return true | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package messages | ||
|
||
type Code string | ||
|
||
const ( | ||
HelloMessage Code = "hello" | ||
OperatorConnected Code = "op-conn" | ||
) | ||
|
||
var LocalMessages = map[Code]map[Locale]string{ | ||
HelloMessage: { | ||
LocaleUK: "Привіт, напиши своє питання - ми допоможемо", | ||
LocaleEN: "Hello, write your question and we will help", | ||
}, | ||
OperatorConnected: { | ||
LocaleUK: "До вас доєднався оператор", | ||
LocaleEN: "An operator has joined you", | ||
}, | ||
} |