1
0

add i18n support for CoopShareTx (#168)

Co-authored-by: Michael Hoennig <michael@hoennig.de>
Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/168
Reviewed-by: Timotheus Pokorra <timotheus.pokorra@hostsharing.net>
This commit is contained in:
Michael Hoennig
2025-04-01 12:18:36 +02:00
parent 413ca0917e
commit 4f00d1b920
6 changed files with 64 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.hs.hosting.asset;
package net.hostsharing.hsadminng.hs.office.coopassets;
import net.hostsharing.hsadminng.config.MessageTranslator;
import net.hostsharing.hsadminng.config.RetroactiveTranslator;
@@ -8,7 +8,7 @@ import org.springframework.stereotype.Service;
// HOWTO translate messages which got created without i18n support, in this case in a PostgreSQL constraint trigger
@Service
public class HsHostingAssetTranslations implements RetroactiveTranslator {
public class HsCoopAssetTranslations implements RetroactiveTranslator {
public static final String ERROR_400_PREFIX = "ERROR: [400] ";

View File

@@ -0,0 +1,26 @@
package net.hostsharing.hsadminng.hs.office.coopshares;
import net.hostsharing.hsadminng.config.MessageTranslator;
import net.hostsharing.hsadminng.config.RetroactiveTranslator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
// HOWTO translate messages which got created without i18n support, in this case in a PostgreSQL constraint trigger
@Service
public class HsCoopShareTranslations implements RetroactiveTranslator {
public static final String ERROR_400_PREFIX = "ERROR: [400] ";
@Autowired
private MessageTranslator messageTranslator;
@Override
public boolean canTranslate(final String message) {
return message.equals("ERROR: [400] coop shares transaction would result in a negative number of shares");
}
@Override
public String translate(final String message) {
return ERROR_400_PREFIX + messageTranslator.translate(message.substring(ERROR_400_PREFIX.length()));
}
}

View File

@@ -2,6 +2,7 @@ package net.hostsharing.hsadminng.hs.office.coopshares;
import io.micrometer.core.annotation.Timed;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import net.hostsharing.hsadminng.config.MessageTranslator;
import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.errors.MultiValidationException;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeCoopSharesApi;
@@ -37,6 +38,9 @@ public class HsOfficeCoopSharesTransactionController implements HsOfficeCoopShar
@Autowired
private StrictMapper mapper;
@Autowired
private MessageTranslator messageTranslator;
@Autowired
private HsOfficeCoopSharesTransactionRepository coopSharesTransactionRepo;
@@ -118,32 +122,31 @@ public class HsOfficeCoopSharesTransactionController implements HsOfficeCoopShar
MultiValidationException.throwIfNotEmpty(violations);
}
private static void validateSubscriptionTransaction(
private void validateSubscriptionTransaction(
final HsOfficeCoopSharesTransactionInsertResource requestBody,
final ArrayList<String> violations) {
if (requestBody.getTransactionType() == SUBSCRIPTION
&& requestBody.getShareCount() < 0) {
violations.add("for %s, shareCount must be positive but is \"%d\"".formatted(
violations.add(messageTranslator.translate("for transactionType={0}, shareCount must be positive but is {1}",
requestBody.getTransactionType(), requestBody.getShareCount()));
}
}
private static void validateCancellationTransaction(
private void validateCancellationTransaction(
final HsOfficeCoopSharesTransactionInsertResource requestBody,
final ArrayList<String> violations) {
if (requestBody.getTransactionType() == CANCELLATION
&& requestBody.getShareCount() > 0) {
violations.add("for %s, shareCount must be negative but is \"%d\"".formatted(
violations.add(messageTranslator.translate("for transactionType={0}, shareCount must be negative but is {1}",
requestBody.getTransactionType(), requestBody.getShareCount()));
}
}
private static void validateshareCount(
private void validateshareCount(
final HsOfficeCoopSharesTransactionInsertResource requestBody,
final ArrayList<String> violations) {
if (requestBody.getShareCount() == 0) {
violations.add("shareCount must not be 0 but is \"%d\"".formatted(
requestBody.getShareCount()));
violations.add(messageTranslator.translate("shareCount must not be 0"));
}
}

View File

@@ -12,6 +12,12 @@ unknown\ authorization\ ticket=unbekanntes Autorisierungs-Ticket
{0}\ "{1}"\ not\ found\ or\ not\ accessible={0} "{1}" nicht gefunden oder nicht zugänglich
but\ is=ist aber
# office.coop-shares
for\ transactionType\={0},\ shareCount\ must\ be\ positive\ but\ is\ {1}=für transactionType={0}, muss shareCount positiv sein, ist aber {1}
for\ transactionType\={0},\ shareCount\ must\ be\ negative\ but\ is\ {1}=für transactionType={0}, muss shareCount negativ sein, ist aber {1}
shareCount\ must\ not\ be\ 0=shareCount darf nicht 0 sein
coop\ shares\ transaction\ would\ result\ in\ a\ negative\ number\ of\ shares=Geschäftsanteile-Transaktion würde zu negativen Geschäftsanteilen führen
# office.coop-assets
either\ {0}\ or\ {1}\ must\ be\ given=entweder {0} oder {1} muss angegeben werden
either\ {0}\ or\ {1}\ must\ be\ given,\ not\ both=entweder {0} oder {1} muss angegeben werden, nicht beide