summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2013-11-08 14:22:21 +0100
committerIvan Timofeev <timofeev.i.s@gmail.com>2013-11-08 08:51:21 -0600
commit3fff431f152f23180e2ce58e7d1dc6b6b45ab332 (patch)
tree3f4c654e78a66a577a1a9f6c1c4bf729e0ded9b7
parent028b550cce4b08b33c9970baf785b6e1bedb4da2 (diff)
"%1 is replaced to ..." ... maybe, or maybe not
Translations may have omitted the %1 placeholder in SCSTR_COLUMN and SCSTR_ROW, or not have it translated newly yet because it was introduced later. In these cases append the column indicator / row number as it was done before. (cherry picked from commit 9b10373edae490d2b9b7f8d733c59b4f63927bec) Conflicts: sc/source/ui/dbgui/filtdlg.cxx sc/source/ui/dbgui/pfiltdlg.cxx sc/source/ui/dbgui/tpsort.cxx sc/source/ui/dbgui/tpsubt.cxx Change-Id: I331cf0c529bebea02277784ea145c202eb6f6fda Reviewed-on: https://gerrit.libreoffice.org/6618 Reviewed-by: Ivan Timofeev <timofeev.i.s@gmail.com> Tested-by: Ivan Timofeev <timofeev.i.s@gmail.com>
-rw-r--r--sc/inc/global.hxx13
-rw-r--r--sc/source/core/data/global.cxx15
-rw-r--r--sc/source/ui/dbgui/filtdlg.cxx4
-rw-r--r--sc/source/ui/dbgui/pfiltdlg.cxx4
-rw-r--r--sc/source/ui/dbgui/tpsort.cxx11
-rw-r--r--sc/source/ui/dbgui/tpsubt.cxx4
6 files changed, 33 insertions, 18 deletions
diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx
index a3f89fb75612..66f332030909 100644
--- a/sc/inc/global.hxx
+++ b/sc/inc/global.hxx
@@ -704,6 +704,19 @@ SC_DLLPUBLIC static const sal_Unicode* FindUnquoted( const sal_Unicode* pStri
/** A static instance of ScFieldEditEngine not capable of resolving
document specific fields, to be used only by ScEditUtil::GetString(). */
static ScFieldEditEngine& GetStaticFieldEditEngine();
+
+ /** Replaces the first occurrence of rPlaceholder in rString with
+ rReplacement, or if rPlaceholder is not found appends one space if
+ rString does not end in a space and appends rReplacement.
+
+ Meant to be used with resource strings ala "Column %1" where a
+ translation may have omitted the %1 placeholder and a simple
+ replacement would end up with nothing replaced so no column indicator
+ in the result string.
+ */
+ SC_DLLPUBLIC static OUString ReplaceOrAppend( const OUString& rString,
+ const OUString& rPlaceholder,
+ const OUString& rReplacement );
};
#endif
diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx
index f75b936dbb67..846ca772acff 100644
--- a/sc/source/core/data/global.cxx
+++ b/sc/source/core/data/global.cxx
@@ -1206,4 +1206,19 @@ ScFieldEditEngine& ScGlobal::GetStaticFieldEditEngine()
return *pFieldEditEngine;
}
+OUString ScGlobal::ReplaceOrAppend( const OUString& rString,
+ const OUString& rPlaceholder, const OUString& rReplacement )
+{
+ if (rString.isEmpty())
+ return rReplacement;
+ sal_Int32 nFound = rString.indexOf( rPlaceholder);
+ if (nFound < 0)
+ {
+ if (rString[rString.getLength()-1] == ' ')
+ return rString + rReplacement;
+ return rString + " " + rReplacement;
+ }
+ return rString.replaceFirst( rPlaceholder, rReplacement, &nFound);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/dbgui/filtdlg.cxx b/sc/source/ui/dbgui/filtdlg.cxx
index 61f5ecb66299..8e39046772fd 100644
--- a/sc/source/ui/dbgui/filtdlg.cxx
+++ b/sc/source/ui/dbgui/filtdlg.cxx
@@ -488,9 +488,7 @@ void ScFilterDlg::FillFieldLists()
aFieldName = pDoc->GetString(col, nFirstRow, nTab);
if (!aBtnHeader.IsChecked() || aFieldName.isEmpty())
{
- OUStringBuffer aBuf;
- aBuf.append(aStrColumn);
- aFieldName = aBuf.makeStringAndClear().replaceAll("%1", ScColToAlpha( col ));
+ aFieldName = ScGlobal::ReplaceOrAppend( aStrColumn, "%1", ScColToAlpha( col ));
}
aLbField1.InsertEntry( aFieldName, i );
aLbField2.InsertEntry( aFieldName, i );
diff --git a/sc/source/ui/dbgui/pfiltdlg.cxx b/sc/source/ui/dbgui/pfiltdlg.cxx
index 3f5f63e899a1..95cec1ce0fea 100644
--- a/sc/source/ui/dbgui/pfiltdlg.cxx
+++ b/sc/source/ui/dbgui/pfiltdlg.cxx
@@ -294,9 +294,7 @@ void ScPivotFilterDlg::FillFieldLists()
aFieldName = pDoc->GetString(col, nFirstRow, nTab);
if ( aFieldName.isEmpty() )
{
- OUStringBuffer aBuf;
- aBuf.append(aStrColumn);
- aFieldName = aBuf.makeStringAndClear().replaceAll("%1", ScColToAlpha( col ));
+ aFieldName = ScGlobal::ReplaceOrAppend( aStrColumn, "%1", ScColToAlpha( col ));
}
aLbField1.InsertEntry( aFieldName, i );
aLbField2.InsertEntry( aFieldName, i );
diff --git a/sc/source/ui/dbgui/tpsort.cxx b/sc/source/ui/dbgui/tpsort.cxx
index 1479313136a5..a0520ea3d1f6 100644
--- a/sc/source/ui/dbgui/tpsort.cxx
+++ b/sc/source/ui/dbgui/tpsort.cxx
@@ -384,9 +384,7 @@ void ScTabPageSortFields::FillFieldLists( sal_uInt16 nStartField )
aFieldName = pDoc->GetString(col, nFirstSortRow, nTab);
if ( !bHasHeader || aFieldName.isEmpty() )
{
- OUStringBuffer aBuf;
- aBuf.append(aStrColumn);
- aFieldName = aBuf.makeStringAndClear().replaceAll("%1", ScColToAlpha( col ));
+ aFieldName = ScGlobal::ReplaceOrAppend( aStrColumn, "%1", ScColToAlpha( col ));
}
nFieldArr.push_back( col );
@@ -407,12 +405,7 @@ void ScTabPageSortFields::FillFieldLists( sal_uInt16 nStartField )
aFieldName = pDoc->GetString(nFirstSortCol, row, nTab);
if ( !bHasHeader || aFieldName.isEmpty() )
{
- OUStringBuffer aBuf;
- OUStringBuffer tempBuf;
-
- aBuf.append(aStrRow);
- tempBuf.append(row+1 );
- aFieldName = aBuf.makeStringAndClear().replaceAll("%1", tempBuf.makeStringAndClear());
+ aFieldName = ScGlobal::ReplaceOrAppend( aStrRow, "%1", OUString::number( row+1));
}
nFieldArr.push_back( row );
diff --git a/sc/source/ui/dbgui/tpsubt.cxx b/sc/source/ui/dbgui/tpsubt.cxx
index b2a9f9a01177..143136294827 100644
--- a/sc/source/ui/dbgui/tpsubt.cxx
+++ b/sc/source/ui/dbgui/tpsubt.cxx
@@ -278,9 +278,7 @@ void ScTpSubTotalGroup::FillListBoxes()
aFieldName = pDoc->GetString(col, nFirstRow, nTab);
if ( aFieldName.isEmpty() )
{
- OUStringBuffer aBuf;
- aBuf.append(aStrColumn);
- aFieldName = aBuf.makeStringAndClear().replaceAll("%1", ScColToAlpha( col ));
+ aFieldName = ScGlobal::ReplaceOrAppend( aStrColumn, "%1", ScColToAlpha( col ));
}
nFieldArr[i] = col;
aLbGroup.InsertEntry( aFieldName, i+1 );