Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localization - Support for any language #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ Code(FakeR) was also taken from the phonegap BarCodeScanner plugin. This code u
https://github.com/wildabeast/BarcodeScanner

## License
MIT
MIT
10 changes: 8 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<header-file src="src/ios/QBImagePicker/QBAssetsViewController.h" />
<source-file src="src/ios/QBImagePicker/QBAssetsViewController.m" />

<resource-file src="src/ios/QBImagePicker/en.lproj/QBImagePicker.strings" />
<resource-file src="src/ios/QBImagePicker/da.lproj/QBImagePicker.strings" />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this removing the english files?

<resource-file src="src/ios/QBImagePicker/QBImagePicker.storyboard" />

<framework src="QuartzCore.framework" />
Expand All @@ -77,13 +77,18 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</config-file>

<source-file src="src/android/Library/src/Localization/Messages.java" target-dir="src/com/synconset"/>
<source-file src="src/android/Library/src/Localization/Language.java" target-dir="src/com/synconset"/>
<source-file src="src/android/Library/src/Localization/English.java" target-dir="src/com/synconset"/>
<source-file src="src/android/Library/src/Localization/Danish.java" target-dir="src/com/synconset"/>

<source-file src="src/android/com/synconset/ImagePicker/ImagePicker.java" target-dir="src/com/synconset" />
<source-file src="src/android/com/synconset/ImagePicker/FakeR.java" target-dir="src/com/synconset" />

<source-file src="src/android/Library/src/ImageFetcher.java" target-dir="src/com/synconset"/>
<source-file src="src/android/Library/src/MultiImageChooserActivity.java" target-dir="src/com/synconset"/>

<source-file src="src/android/Library/res/anim/image_pop_in.xml" target-dir="res/anim"/>
<source-file src="src/android/Library/res/anim/image_pop_in.xml" target-dir="res/anim"/>
<source-file src="src/android/Library/res/drawable/grid_background.xml" target-dir="res/drawable"/>
<source-file src="src/android/Library/res/drawable-hdpi/image_bg.9.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/Library/res/drawable-hdpi/loading_icon.png" target-dir="res/drawable-hdpi"/>
Expand All @@ -102,6 +107,7 @@
<source-file src="src/android/Library/res/layout/actionbar_done_button.xml" target-dir="res/layout"/>
<source-file src="src/android/Library/res/layout/multiselectorgrid.xml" target-dir="res/layout"/>
<source-file src="src/android/Library/res/values/multiimagechooser_strings_en.xml" target-dir="res/values"/>
<source-file src="src/android/Library/res/values-da/multiimagechooser_strings_da.xml" target-dir="res/values-da"/>
<source-file src="src/android/Library/res/values/themes.xml" target-dir="res/values"/>

<!--
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="multi_app_name">MultiImageChooser</string>
<string name="free_version_label">Free version - Images left: %d</string>
<string name="error_database">Der skete en fejl ved åbningen af billede-databasen. Rapporter venligst problemet.</string>
<string name="requesting_thumbnails">Indlæser thumbnails, vent venligst.</string>
<string name="discard">Annuller</string>
<string name="done">OK</string>
</resources>
5 changes: 5 additions & 0 deletions src/android/Library/res/values-da/themes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme.Holo.Light">
</style>
</resources>
14 changes: 14 additions & 0 deletions src/android/Library/src/Localization/Danish.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.synconset;

public class Danish extends Language {
public Danish() {
super("da");

addMessage("PROCESS_IMAGES_TITLE", "Indlæser billeder");
addMessage("PROCESS_IMAGES_MESSAGE", "Dette tager måske lidt tid");
addMessage("MAXIMUM_PHOTOS", "Maximum %d billeder");
addMessage("MAXIMUM_SELECT_PHOTOS", "Du kan kun vælge %d billeder ad gangen.");
addMessage("OUT_OF_MEMORY", "Kunne ikke indlæse billedet i hukommelsen");
addMessage("UNABLE_TO_OPEN_IMAGE", "Kunne ikke åbne billedet.");
}
}
14 changes: 14 additions & 0 deletions src/android/Library/src/Localization/English.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.synconset;

public class English extends Language {
public English() {
super("en");

addMessage("PROCESS_IMAGES_TITLE", "Processing Images");
addMessage("PROCESS_IMAGES_MESSAGE", "This may take a few moments");
addMessage("MAXIMUM_PHOTOS", "Maximum %d Photos");
addMessage("MAXIMUM_SELECT_PHOTOS", "You can only select %d photos at a time.");
addMessage("OUT_OF_MEMORY", "Unable to load image into memory.");
addMessage("UNABLE_TO_OPEN_IMAGE", "The image file could not be opened.");
}
}
23 changes: 23 additions & 0 deletions src/android/Library/src/Localization/Language.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.synconset;

import java.util.HashMap;

public class Language {
private HashMap<String, String> _messages;

protected Language(String code) {
_messages = new HashMap<String, String>();
}

protected void addMessage(String messageName, String message) {
_messages.put(messageName, message);
}

public String getMessage(String messageName) {
if (!_messages.containsKey(messageName)) {
return "";
}

return _messages.get(messageName);
}
}
34 changes: 34 additions & 0 deletions src/android/Library/src/Localization/Messages.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.synconset;

import java.util.Locale;
import java.util.HashMap;

public final class Messages {
private static HashMap<String, Language> _languages;

private static void initializeLanguages() {
_languages = new HashMap<String, Language>();

_languages.put("en", new English());
_languages.put("da", new Danish());
}

public static String get(String messageName) {
String languageName = Locale.getDefault().getLanguage();

return get(languageName, messageName);
}

public static String get(String languageName, String messageName) {
if (_languages == null) {
initializeLanguages();
}

if (!_languages.containsKey(languageName)) {
languageName = "en";
}

Language language = _languages.get(languageName);
return language.getMessage(messageName);
}
}
Loading