Tracker: fix localization of warning when editing system dirs

Programatically generating a string usually doesn't work well with
localization. Better unfold all the possiblities.

Moreover, the callers of the functions had a long if condition with
3 B_TRANSLATE calls embedded in, and there was an erroneous ; at the end
of those, so the supposedly protected statement was executed anyway.

Fixes #12747.
This commit is contained in:
Adrien Destugues 2016-08-21 16:42:10 +02:00
parent a8aeb8a9e2
commit 4072c4f1b3
4 changed files with 82 additions and 73 deletions

View File

@ -621,9 +621,8 @@ enum {
bool bool
ConfirmChangeIfWellKnownDirectory(const BEntry* entry, ConfirmChangeIfWellKnownDirectory(const BEntry* entry, DestructiveAction action,
const char* ifYouDoAction, const char* toDoAction, bool dontAsk, int32* confirmedAlready)
const char* toConfirmAction, bool dontAsk, int32* confirmedAlready)
{ {
// Don't let the user casually move/change important files/folders // Don't let the user casually move/change important files/folders
// //
@ -646,41 +645,76 @@ ConfirmChangeIfWellKnownDirectory(const BEntry* entry,
bool requireOverride = true; bool requireOverride = true;
if (DirectoryMatchesOrContains(entry, B_SYSTEM_DIRECTORY)) { if (DirectoryMatchesOrContains(entry, B_SYSTEM_DIRECTORY)) {
warning.SetTo( if (action == kRename) {
B_TRANSLATE("If you %ifYouDoAction the system folder or its " warning.SetTo(
"contents, you won't be able to boot %osName!\n\nAre you sure " B_TRANSLATE("If you rename the system folder or its "
"you want to do this?\n\nTo %toDoAction the system folder or its " "contents, you won't be able to boot %osName!\n\nAre you sure "
"contents anyway, hold down the Shift key and click " "you want to do this?\n\nTo rename the system folder or its "
"\"%toConfirmAction\".")); "contents anyway, hold down the Shift key and click "
"\"Rename\"."));
} else if(action == kMove) {
warning.SetTo(
B_TRANSLATE("If you move the system folder or its "
"contents, you won't be able to boot %osName!\n\nAre you sure "
"you want to do this?\n\nTo move the system folder or its "
"contents anyway, hold down the Shift key and click "
"\"Move\"."));
} else {
warning.SetTo(
B_TRANSLATE("If you alter the system folder or its "
"contents, you won't be able to boot %osName!\n\nAre you sure "
"you want to do this?\n\nTo alter the system folder or its "
"contents anyway, hold down the Shift key and click "
"\"I know what I'm doing\"."));
}
} else if (DirectoryMatches(entry, B_USER_DIRECTORY)) { } else if (DirectoryMatches(entry, B_USER_DIRECTORY)) {
warning .SetTo( if (action == kRename) {
B_TRANSLATE("If you %ifYouDoAction the home folder, %osName " warning .SetTo(
"may not behave properly!\n\nAre you sure you want to do this?" B_TRANSLATE("If you rename the home folder, %osName "
"\n\nTo %toDoAction the home folder anyway, hold down the " "may not behave properly!\n\nAre you sure you want to do this?"
"Shift key and click \"%toConfirmAction\".")); "\n\nTo rename the home folder anyway, hold down the "
"Shift key and click \"Move\"."));
} else if (action == kMove) {
warning .SetTo(
B_TRANSLATE("If you move the home folder, %osName "
"may not behave properly!\n\nAre you sure you want to do this?"
"\n\nTo move the home folder anyway, hold down the "
"Shift key and click \"Move\"."));
} else {
warning .SetTo(
B_TRANSLATE("If you alter the home folder, %osName "
"may not behave properly!\n\nAre you sure you want to do this?"
"\n\nTo alter the home folder anyway, hold down the "
"Shift key and click \"I know what I'm doing\"."));
}
} else if (DirectoryMatchesOrContains(entry, B_USER_CONFIG_DIRECTORY) } else if (DirectoryMatchesOrContains(entry, B_USER_CONFIG_DIRECTORY)
|| DirectoryMatchesOrContains(entry, B_SYSTEM_SETTINGS_DIRECTORY)) { || DirectoryMatchesOrContains(entry, B_SYSTEM_SETTINGS_DIRECTORY)) {
if (action == kRename) {
warning.SetTo(
B_TRANSLATE("If you rename %target, %osName may not behave "
"properly!\n\nAre you sure you want to do this?"));
} else if (action == kMove) {
warning.SetTo(
B_TRANSLATE("If you move %target, %osName may not behave "
"properly!\n\nAre you sure you want to do this?"));
} else {
warning.SetTo(
B_TRANSLATE("If you alter %target, %osName may not behave "
"properly!\n\nAre you sure you want to do this?"));
}
if (DirectoryMatchesOrContains(entry, "beos_mime", if (DirectoryMatchesOrContains(entry, "beos_mime",
B_USER_SETTINGS_DIRECTORY) B_USER_SETTINGS_DIRECTORY)
|| DirectoryMatchesOrContains(entry, "beos_mime", || DirectoryMatchesOrContains(entry, "beos_mime",
B_SYSTEM_SETTINGS_DIRECTORY)) { B_SYSTEM_SETTINGS_DIRECTORY)) {
warning.SetTo( warning.ReplaceFirst("%target", "the MIME settings");
B_TRANSLATE("If you %ifYouDoAction the mime settings, "
"%osName may not behave properly!\n\nAre you sure you want "
"to do this?"));
requireOverride = false; requireOverride = false;
} else if (DirectoryMatches(entry, B_USER_CONFIG_DIRECTORY)) { } else if (DirectoryMatches(entry, B_USER_CONFIG_DIRECTORY)) {
warning.SetTo( warning.ReplaceFirst("%target", "the config folder");
B_TRANSLATE("If you %ifYouDoAction the config folder, "
"%osName may not behave properly!\n\nAre you sure you want "
"to do this?"));
requireOverride = false; requireOverride = false;
} else if (DirectoryMatches(entry, B_USER_SETTINGS_DIRECTORY) } else if (DirectoryMatches(entry, B_USER_SETTINGS_DIRECTORY)
|| DirectoryMatches(entry, B_SYSTEM_SETTINGS_DIRECTORY)) { || DirectoryMatches(entry, B_SYSTEM_SETTINGS_DIRECTORY)) {
warning.SetTo( warning.ReplaceFirst("%target", "the settings folder");
B_TRANSLATE("If you %ifYouDoAction the settings folder, "
"%osName may not behave properly!\n\nAre you sure you want "
"to do this?"));
requireOverride = false; requireOverride = false;
} }
} }
@ -702,11 +736,15 @@ ConfirmChangeIfWellKnownDirectory(const BEntry* entry,
else else
warning.ReplaceFirst("%osName", name.sysname); warning.ReplaceFirst("%osName", name.sysname);
warning.ReplaceFirst("%ifYouDoAction", ifYouDoAction); BString buttonLabel;
warning.ReplaceFirst("%toDoAction", toDoAction); if (action == kRename) {
warning.ReplaceFirst("%toConfirmAction", toConfirmAction); buttonLabel = B_TRANSLATE_COMMENT("Rename", "button label");
} else if (action == kMove) {
BString buttonLabel(toConfirmAction); buttonLabel = B_TRANSLATE_COMMENT("Move", "button label");
} else {
buttonLabel = B_TRANSLATE_COMMENT("I know what I'm doing",
"button label");
}
OverrideAlert* alert = new OverrideAlert("", warning.String(), OverrideAlert* alert = new OverrideAlert("", warning.String(),
buttonLabel.String(), (requireOverride ? B_SHIFT_KEY : 0), buttonLabel.String(), (requireOverride ? B_SHIFT_KEY : 0),
@ -770,15 +808,7 @@ InitCopy(CopyLoopControl* loopControl, uint32 moveMode,
return B_ERROR; return B_ERROR;
} }
if (moveMode == kMoveSelectionTo if (moveMode == kMoveSelectionTo
&& !ConfirmChangeIfWellKnownDirectory(&entry, && !ConfirmChangeIfWellKnownDirectory(&entry, kMove,
B_TRANSLATE_COMMENT("move",
"As in 'if you move this folder...' (en) "
"'Wird dieser Ordner verschoben...' (de)"),
B_TRANSLATE_COMMENT("move",
"As in 'to move this folder...' (en) "
"Um diesen Ordner zu verschieben...' (de)"),
B_TRANSLATE_COMMENT("Move",
"Button label, 'Move' (en), 'Verschieben' (de)"),
false, &askOnceOnly)) { false, &askOnceOnly)) {
return B_ERROR; return B_ERROR;
} }

View File

@ -255,12 +255,13 @@ status_t FSFindTrackerSettingsDir(BPath*, bool autoCreate = true);
bool FSIsDeskDir(const BEntry*); bool FSIsDeskDir(const BEntry*);
// two separate ifYouDoAction and toDoAction versions are needed for enum DestructiveAction {
// localization purposes. The first one is used in "If you do action..." kRename,
// sentence, the second one in the "To do action" sentence. kMove
};
bool ConfirmChangeIfWellKnownDirectory(const BEntry* entry, bool ConfirmChangeIfWellKnownDirectory(const BEntry* entry,
const char* ifYouDoAction, const char* toDoAction, DestructiveAction action, bool dontAsk = false,
const char* toConfirmAction, bool dontAsk = false,
int32* confirmedAlready = NULL); int32* confirmedAlready = NULL);
bool CheckDevicesEqual(const entry_ref* entry, const Model* targetModel); bool CheckDevicesEqual(const entry_ref* entry, const Model* targetModel);

View File

@ -442,16 +442,9 @@ BInfoWindow::MessageReceived(BMessage* message)
{ {
BEntry entry(fModel->EntryRef()); BEntry entry(fModel->EntryRef());
if (!fModel->HasLocalizedName() if (!fModel->HasLocalizedName()
&& ConfirmChangeIfWellKnownDirectory(&entry, && ConfirmChangeIfWellKnownDirectory(&entry, kRename)) {
B_TRANSLATE_COMMENT("rename",
"As in 'if you rename this folder...' (en) "
"'Wird dieser Ordner umbenannt...' (de)"),
B_TRANSLATE_COMMENT("rename",
"As in 'to rename this folder...' (en) "
"'Um diesen Ordner umzubenennen...' (de)"),
B_TRANSLATE_COMMENT("Rename",
"Button label, 'Rename' (en), 'Umbenennen' (de)")));
fAttributeView->BeginEditingTitle(); fAttributeView->BeginEditingTitle();
}
break; break;
} }
@ -1246,17 +1239,9 @@ AttributeView::MouseDown(BPoint where)
fTrackingState = path_track; fTrackingState = path_track;
} else if (fTitleRect.Contains(where)) { } else if (fTitleRect.Contains(where)) {
if (!fModel->HasLocalizedName() if (!fModel->HasLocalizedName()
&& ConfirmChangeIfWellKnownDirectory(&entry, && ConfirmChangeIfWellKnownDirectory(&entry, kRename)) {
B_TRANSLATE_COMMENT("rename",
"As in 'if you rename this folder...' (en) "
"'Wird dieser Ordner umbenannt...' (de)"),
B_TRANSLATE_COMMENT("rename",
"As in 'to rename this folder...' (en) "
"'Um diesen Ordner umzubenennen...' (de)"),
B_TRANSLATE_COMMENT("Rename",
"Button label, 'Rename' (en), 'Umbenennen' (de)"), true)
&& fTitleEditView == 0);
BeginEditingTitle(); BeginEditingTitle();
}
} else if (fTitleEditView) { } else if (fTitleEditView) {
FinishEditingTitle(true); FinishEditingTitle(true);
} else if (fSizeRect.Contains(where)) { } else if (fSizeRect.Contains(where)) {

View File

@ -353,16 +353,9 @@ BTextWidget::StartEdit(BRect bounds, BPoseView* view, BPose* pose)
BEntry entry(pose->TargetModel()->EntryRef()); BEntry entry(pose->TargetModel()->EntryRef());
if (entry.InitCheck() == B_OK if (entry.InitCheck() == B_OK
&& !ConfirmChangeIfWellKnownDirectory(&entry, && !ConfirmChangeIfWellKnownDirectory(&entry, kRename)) {
B_TRANSLATE_COMMENT("rename",
"As in 'if you rename this folder...' (en) "
"'Wird dieser Ordner umbenannt...' (de)"),
B_TRANSLATE_COMMENT("rename",
"As in 'to rename this folder...' (en) "
"'Um diesen Ordner umzubenennen...' (de)"),
B_TRANSLATE_COMMENT("Rename",
"Button label, 'Rename' (en), 'Umbenennen' (de)")))
return; return;
}
// get bounds with full text length // get bounds with full text length
BRect rect(bounds); BRect rect(bounds);