Skip to content

Commit

Permalink
Fixed: Language list when building outside of project root
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner committed Aug 25, 2017
1 parent c659c77 commit eea6f92
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### v1.2.4
- Updated: Readme
- Fixed: Language list when building outside of project root

### v1.2.3
- Added: Option to change app language
Expand Down
20 changes: 10 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ android {
sourceSets { main { assets.srcDirs = ['src/main/assets', '../assets'] } }
}

String[] getUsedAndroidLanguages(){
Set<String> langs = new HashSet<>();
String[] resFolders = new File("app/src/main/res").list()
for(resFolder in resFolders){
if (resFolder.startsWith("values-")){
String[] files = new File("app/src/main/res/"+resFolder).list();
for (file in files){
if (file.startsWith("strings") && file.endsWith(".xml")){
langs.add(resFolder.replace("values-",""))
break;
@SuppressWarnings(["UnnecessaryQualifiedReference", "SpellCheckingInspection"])
static String[] getUsedAndroidLanguages() {
Set<String> langs = new HashSet<>()
new File('.').eachFileRecurse(groovy.io.FileType.DIRECTORIES) {
final foldername = it.name
if (foldername.startsWith('values-') && !it.canonicalPath.contains("build" + File.separator + "intermediates")) {
new File(it.toString()).eachFileRecurse(groovy.io.FileType.FILES) {
if (it.name.toLowerCase().endsWith(".xml") && it.getCanonicalFile().getText('UTF-8').contains("<string")) {
langs.add(foldername.replace("values-", ""))

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,26 @@
* opoc/Helpers
* BuildConfig field can be defined by using the method below
buildConfigField("String[]", "APPLICATION_LANGUAGES", '{' + getUsedAndroidLanguages().collect {"\"${it}\""}.join(",") + '}')
String[] getUsedAndroidLanguages(){
Set<String> langs = new HashSet<>();
String[] resFolders = new File("app/src/main/res").list()
for(resFolder in resFolders){
if (resFolder.startsWith("values-")){
String[] files = new File("app/src/main/res/"+resFolder).list();
for (file in files){
if (file.startsWith("strings") && file.endsWith(".xml")){
langs.add(resFolder.replace("values-",""))
break;
}
buildConfigField("String[]", "APPLICATION_LANGUAGES", '{' + getUsedAndroidLanguages().collect {"\"${it}\""}.join(",") + '}')
@SuppressWarnings(["UnnecessaryQualifiedReference", "SpellCheckingInspection"])
static String[] getUsedAndroidLanguages() {
Set<String> langs = new HashSet<>()
new File('.').eachFileRecurse(groovy.io.FileType.DIRECTORIES) {
final foldername = it.name
if (foldername.startsWith('values-') && !it.canonicalPath.contains("build" + File.separator + "intermediates")) {
new File(it.toString()).eachFileRecurse(groovy.io.FileType.FILES) {
if (it.name.toLowerCase().endsWith(".xml") && it.getCanonicalFile().getText('UTF-8').contains("<string")) {
langs.add(foldername.replace("values-", ""))
}
}
}
return langs.toArray(new String[langs.size()])
}
return langs.toArray(new String[langs.size()])
}
* Summary: Change language of this app. Restart app for changes to take effect
* Define element in Preferences-XML:
<!--suppress AndroidDomInspection -->
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@
<string name="pref_title__is_statusbar_hidden">Esconder barra de status</string>
<string name="pref_summary__picture_quality__percent">Qualidade e tamanho. Valores altos causam mais tempo de carregamento. Dependendo do processador e o tamanho da imagem o app pode falhar se o valor extrapolar 25%.</string>
<string name="pref_title__thumbnail_quality__percent">Qualidade da pré-visualização</string>

<!-- Language -->
<string name="pref_title__language">Idioma</string>
<string name="pref_desc__language">Muda o idioma do aplicativo. Reinicie o aplicativo para que as alterações entrem em vigor</string>
</resources>

0 comments on commit eea6f92

Please sign in to comment.