-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from Gmugra/163_localization_support_for_erro…
…r_messages #163 : toml/json: Localization support for error messages
- Loading branch information
Showing
12 changed files
with
113 additions
and
9 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
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
45 changes: 45 additions & 0 deletions
45
json/src/main/java/net/cactusthorn/config/extras/json/util/JsonMessages.java
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,45 @@ | ||
/* | ||
* Copyright (C) 2021, Alexei Khatskevich | ||
* | ||
* Licensed under the BSD 3-Clause license. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://github.com/Gmugra/net.cactusthorn.config/blob/main/LICENSE | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package net.cactusthorn.config.extras.json.util; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Locale; | ||
import java.util.ResourceBundle; | ||
|
||
public final class JsonMessages { | ||
|
||
private static final String BANDLE = JsonMessages.class.getName(); | ||
private static final ResourceBundle MESSAGES = ResourceBundle.getBundle(BANDLE, Locale.getDefault()); | ||
|
||
private JsonMessages() { | ||
} | ||
|
||
public enum Key { | ||
ROOT_OBJECT, OBJECTS_IN_ARRAY, ARRAYS_IN_ARRAY | ||
} | ||
|
||
public static String msg(Key key) { | ||
return MESSAGES.getString(key.name()); | ||
} | ||
|
||
public static String msg(Key key, Object argument) { | ||
return MessageFormat.format(MESSAGES.getString(key.name()), argument); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
json/src/main/resources/net/cactusthorn/config/extras/json/util/JsonMessages.properties
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,3 @@ | ||
ROOT_OBJECT=root must be object | ||
OBJECTS_IN_ARRAY={0} - objects in array are not supported | ||
ARRAYS_IN_ARRAY={0} - arrays in array are not supported |
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
41 changes: 41 additions & 0 deletions
41
toml/src/main/java/net/cactusthorn/config/extras/toml/util/TomlMessages.java
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,41 @@ | ||
/* | ||
* Copyright (C) 2021, Alexei Khatskevich | ||
* | ||
* Licensed under the BSD 3-Clause license. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://github.com/Gmugra/net.cactusthorn.config/blob/main/LICENSE | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package net.cactusthorn.config.extras.toml.util; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Locale; | ||
import java.util.ResourceBundle; | ||
|
||
public final class TomlMessages { | ||
|
||
private static final String BANDLE = TomlMessages.class.getName(); | ||
private static final ResourceBundle MESSAGES = ResourceBundle.getBundle(BANDLE, Locale.getDefault()); | ||
|
||
private TomlMessages() { | ||
} | ||
|
||
public enum Key { | ||
ARRAYS_IN_ARRAY, TABLES_IN_ARRAY | ||
} | ||
|
||
public static String msg(Key key, Object argument) { | ||
return MessageFormat.format(MESSAGES.getString(key.name()), argument); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
toml/src/main/resources/net/cactusthorn/config/extras/toml/util/TomlMessages.properties
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,2 @@ | ||
ARRAYS_IN_ARRAY={0} - arrays in array are not supported | ||
TABLES_IN_ARRAY={0} - tables in array are not supported |
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