Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F56401173
SuhaylTranslationRegistry.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
SuhaylTranslationRegistry.java
View Options
package
org.eu.loupsgris.quilvaryn.config
;
import
net.kyori.adventure.key.Key
;
import
net.kyori.adventure.translation.GlobalTranslator
;
import
net.kyori.adventure.translation.TranslationRegistry
;
import
org.eu.loupsgris.quilvaryn.SuhaylPlugin
;
import
org.eu.loupsgris.quilvaryn.utils.ResourceLoader
;
import
java.io.InputStreamReader
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Locale
;
import
java.util.PropertyResourceBundle
;
import
java.util.ResourceBundle
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
public
class
SuhaylTranslationRegistry
{
private
final
Logger
logger
;
private
final
ResourceLoader
loader
;
public
SuhaylTranslationRegistry
(
Logger
logger
,
ResourceLoader
loader
)
{
this
.
logger
=
logger
;
this
.
loader
=
loader
;
}
public
void
load
()
{
Key
key
=
Key
.
key
(
SuhaylPlugin
.
NAMESPACE
,
"translations"
);
TranslationRegistry
registry
=
TranslationRegistry
.
create
(
key
);
Locale
[]
frenchLocales
=
new
Locale
[]{
Locale
.
FRENCH
,
Locale
.
FRANCE
,
Locale
.
CANADA_FRENCH
,
};
loadBundle
(
"l10n/messages_en.properties"
,
Locale
.
ENGLISH
,
registry
);
loadBundle
(
"l10n/messages_fr.properties"
,
frenchLocales
,
registry
);
registry
.
defaultLocale
(
Locale
.
ENGLISH
);
GlobalTranslator
.
translator
().
addSource
(
registry
);
}
private
void
loadBundle
(
String
path
,
Locale
locale
,
TranslationRegistry
registry
)
{
Locale
[]
locales
=
{
locale
};
loadBundle
(
path
,
locales
,
registry
);
}
private
void
loadBundle
(
String
path
,
Locale
[]
locales
,
TranslationRegistry
registry
)
{
try
(
var
stream
=
loader
.
open
(
path
))
{
if
(
stream
==
null
)
{
logger
.
warning
(
"Missing translation file: "
+
path
);
return
;
}
ResourceBundle
bundle
=
new
PropertyResourceBundle
(
new
InputStreamReader
(
stream
,
StandardCharsets
.
UTF_8
)
);
for
(
Locale
locale
:
locales
)
{
registry
.
registerAll
(
locale
,
bundle
,
true
);
}
}
catch
(
Exception
e
)
{
logger
.
log
(
Level
.
SEVERE
,
"Error loading translations file: "
+
path
,
e
);
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sat, Nov 7, 19:55 (1 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4253387
Default Alt Text
SuhaylTranslationRegistry.java (2 KB)
Attached To
Mode
rQVR Quilvaryn
Attached
Detach File
Event Timeline
Log In to Comment