Skip to content

Commit

Permalink
Update localization
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Dec 6, 2024
1 parent f3c79ea commit 30904d8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 26 deletions.
16 changes: 9 additions & 7 deletions cpp/command/command_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ bool CommandExecutor::Attach(const CommandContext &context, const PbDeviceDefini

const string &filename = GetParam(pb_device, "file");

const auto device = CreateDevice(context, type, lun, filename);
const auto device = CreateDevice(context, pb_device, filename);
if (!device) {
return false;
}
Expand Down Expand Up @@ -613,16 +613,18 @@ bool CommandExecutor::EnsureLun0(const CommandContext &context, const PbCommand
true : context.ReturnLocalizedError(LocalizationKey::ERROR_MISSING_LUN0, to_string((*it).first));
}

shared_ptr<PrimaryDevice> CommandExecutor::CreateDevice(const CommandContext &context, const PbDeviceType type,
int lun, const string &filename) const
shared_ptr<PrimaryDevice> CommandExecutor::CreateDevice(const CommandContext &context,
const PbDeviceDefinition &pb_device, const string &filename) const
{
auto device = DeviceFactory::Instance().CreateDevice(type, lun, filename);
auto device = DeviceFactory::Instance().CreateDevice(pb_device.type(), pb_device.unit(), filename);
if (!device) {
if (type == UNDEFINED) {
context.ReturnLocalizedError(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, filename);
if (pb_device.type() == UNDEFINED) {
context.ReturnLocalizedError(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, to_string(pb_device.id()),
to_string(pb_device.unit()), filename);
}
else {
context.ReturnLocalizedError(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, PbDeviceType_Name(type));
context.ReturnLocalizedError(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, to_string(pb_device.id()),
to_string(pb_device.unit()), PbDeviceType_Name(pb_device.type()));
}

return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion cpp/command/command_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CommandExecutor
bool ValidateImageFile(const CommandContext&, StorageDevice&, const string&) const;
bool EnsureLun0(const CommandContext&, const PbCommand&) const;
bool ValidateDevice(const CommandContext&, const PbDeviceDefinition&) const;
shared_ptr<PrimaryDevice> CreateDevice(const CommandContext&, const PbDeviceType, int, const string&) const;
shared_ptr<PrimaryDevice> CreateDevice(const CommandContext&, const PbDeviceDefinition&, const string&) const;
bool SetBlockSize(const CommandContext&, shared_ptr<PrimaryDevice>, int) const;

mutex& GetExecutionLocker()
Expand Down
28 changes: 15 additions & 13 deletions cpp/command/command_localizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,24 @@ CommandLocalizer::CommandLocalizer()
Add(LocalizationKey::ERROR_NON_EXISTING_UNIT, "es", "Comando para ID %1 inexistente, unidad %2");
Add(LocalizationKey::ERROR_NON_EXISTING_UNIT, "zh", "不存在的 ID %1, 单元 %2 的指令");

Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "en", "Unknown device type %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "de", "Unbekannter Gerätetyp %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "sv", "Obekant enhetstyp: %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "fr", "Type de périphérique inconnu %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "es", "Tipo de dispositivo desconocido %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "zh", "未知设备类型 %1");

Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "en", "Device type required for unknown extension of file '%1'");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "en", "%1:%2: Unknown device type %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "de", "%1:%2: Unbekannter Gerätetyp %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "sv", "%1:%2: Obekant enhetstyp: %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "fr", "%1:%2: Type de périphérique inconnu %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "es", "%1:%2: Tipo de dispositivo desconocido %1");
Add(LocalizationKey::ERROR_UNKNOWN_DEVICE_TYPE, "zh", "%1:%2: 未知设备类型 %1");

Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "en",
"%1:%2: Device type required for unknown extension of file '%1'");
Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "de",
"Gerätetyp erforderlich für unbekannte Extension der Datei '%1'");
Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "sv", "Man måste ange enhetstyp för obekant filändelse '%1'");
"%1:%2: Gerätetyp erforderlich für unbekannte Extension der Datei '%1'");
Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "sv",
"%1:%2: Man måste ange enhetstyp för obekant filändelse '%1'");
Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "fr",
"Type de périphérique requis pour extension inconnue du fichier '%1'");
"%1:%2: Type de périphérique requis pour extension inconnue du fichier '%1'");
Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "es",
"Tipo de dispositivo requerido para la extensión desconocida del archivo '%1'");
Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "zh", "文件'%1'的未知扩展名所需的设备类型");
"%1:%2: Tipo de dispositivo requerido para la extensión desconocida del archivo '%1'");
Add(LocalizationKey::ERROR_MISSING_DEVICE_TYPE, "zh", "%1:%2: 文件'%1'的未知扩展名所需的设备类型");

Add(LocalizationKey::ERROR_DUPLICATE_ID, "en", "Duplicate ID %1, unit %2");
Add(LocalizationKey::ERROR_DUPLICATE_ID, "de", "Doppelte ID %1, Einheit %2");
Expand Down
2 changes: 1 addition & 1 deletion cpp/shared/s2p_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
const int s2p_major_version = 4;
const int s2p_minor_version = 1;
const int s2p_revision = 0;
const std::string s2p_suffix = "-rc1";
const std::string s2p_suffix = "";
13 changes: 9 additions & 4 deletions cpp/test/command_executor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,21 @@ TEST(CommandExecutorTest, CreateDevice)
const auto bus = make_shared<MockBus>();
ControllerFactory controller_factory;
const auto executor = make_shared<CommandExecutor>(*bus, controller_factory);
PbDeviceDefinition device;
PbCommand command;
CommandContext context(command);

EXPECT_EQ(nullptr, executor->CreateDevice(context, UNDEFINED, 0, ""));
device.set_type(UNDEFINED);
EXPECT_EQ(nullptr, executor->CreateDevice(context, device, ""));
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
EXPECT_EQ(nullptr, executor->CreateDevice(context, SCBR, 0, ""));
device.set_type(SCBR);
EXPECT_EQ(nullptr, executor->CreateDevice(context, device, ""));
#pragma GCC diagnostic pop
EXPECT_NE(nullptr, executor->CreateDevice(context, UNDEFINED, 0, "services"));
EXPECT_NE(nullptr, executor->CreateDevice(context, SCHS, 0, ""));
device.set_type(UNDEFINED);
EXPECT_NE(nullptr, executor->CreateDevice(context, device, "services"));
device.set_type(SCHS);
EXPECT_NE(nullptr, executor->CreateDevice(context, device, ""));
}

TEST(CommandExecutorTest, SetBlockSize)
Expand Down

0 comments on commit 30904d8

Please sign in to comment.