Move locale name string out of Resource class into gettext file
Move locale name string out of Resource class into gettext file

Too many people missed the LocaleToName step in Resource.class.php when
submitting translations.
It would make more sense to move this into the gettext file so the
translator can actually name the language properly, rather than me
guessing at the right translation of the name of the language.
I'll have to rely on the person reading the note I left and making sure
they don't just translate "English" into their language instead of
putting the name of their actual language.

--- a/include/Resource.class.php
+++ b/include/Resource.class.php
@@ -118,23 +118,27 @@
 	 */
 	public static function LocaleToName($locale)
 	{
-		switch ($locale) {
-			case 'en_US':
-				return 'English';
-			case 'fr_FR':
-				return 'Français';
-			case 'de_DE':
-				return 'Deutsch';
-			case 'ja_JP':
-				return '日本語';
-			case 'ru_RU':
-				return 'Русский';
-			case 'zh_CN':
-				return '中文简体';
-			case 'zz_Debug':
-				return 'Gibberish';
-		}
-		return '';
+		$localeName = __('English');		// for xgettext extraction
+
+		if (self::$currentLocale == $locale) {
+			return $localeName;
+		}
+
+		$localeReader = GitPHP_Resource::CreateLocale($locale);
+		if (!$localeReader) {
+			return '';
+		}
+
+		$localeName = $localeReader->translate('English');
+
+		if (!(($locale == 'en_US') || ($locale == 'en'))) {
+			if ($localeName == 'English') {
+				// someone didn't translate the language name - don't mislabel it as english
+				return '';
+			}
+		}
+
+		return $localeName;
 	}
 
 	/**
@@ -243,16 +247,37 @@
 		self::$instance = null;
 		self::$currentLocale = '';
 
+		$localeReader = GitPHP_Resource::CreateLocale($locale);
+		if (!$localeReader) {
+			return false;
+		}
+
+		self::$instance = $localeReader;
+		self::$currentLocale = $locale;
+		return true;
+	}
+
+	/**
+	 * CreateLocale
+	 *
+	 * Creates a locale reader object
+	 *
+	 * @access private
+	 * @static
+	 * @param string $locale locale to create
+	 * @return mixed locale reader object or null on failure
+	 */
+	private static function CreateLocale($locale)
+	{
 		$reader = null;
 		if (!(($locale == 'en_US') || ($locale == 'en'))) {
 			$reader = new FileReader(GITPHP_LOCALEDIR . $locale . '/gitphp.mo');
-			if (!$reader)
-				return false;
-		}
-
-		self::$instance = new gettext_reader($reader);
-		self::$currentLocale = $locale;
-		return true;
+			if (!$reader) {
+				return null;
+			}
+		}
+
+		return new gettext_reader($reader);
 	}
 
 }

--- a/locale/de_DE/gitphp.po
+++ b/locale/de_DE/gitphp.po
@@ -654,4 +654,84 @@
 msgid "set"
 msgstr ""
 
-
+# Caption for the Atom button for a project
+# Atom is a standard web feed format
+#: templates/projectbase.tpl
+msgid "Atom"
+msgstr ""
+
+# Used as the title of the Atom controller
+# Atom is a standard web feed format
+#: include/controller/Controller_Feed.class.php:97
+msgid "atom"
+msgstr ""
+
+# Used as an error message when memcache is turned
+# on without the appropriate PHP extension installed
+#: include/smartyplugins/cacheresource.memcache.php:85
+msgid ""
+"The Memcached or Memcache PHP extension is required for Memcache support"
+msgstr ""
+
+# Message when searching the project list, and nothing is found
+# %1: the search string entered
+#: templates/jsconst.tpl
+#: templates/projectlist.tpl
+msgid "No matches found for \"%1\""
+msgstr ""
+
+# Label for the field to search the project list
+#: templates/projectlist.tpl
+msgid "Search projects"
+msgstr ""
+
+# Error message displayed when the git executable isn't found or doesn't work
+# %1$s: the git executable the system is trying to run
+# %2$s: the config value the user needs to set to specify the correct path
+#: index.php:140
+#, php-format
+msgid ""
+"Could not run the git executable \"%1$s\".  You may need to set the \"%2$s\" "
+"config value."
+msgstr ""
+
+# Error message displayed when the diff executable isn't found or doesn't work
+# %1$s: the diff executable the system is trying to run
+# %2$s: the config value the user needs to set to specify the correct path
+#: index.php:145
+#, php-format
+msgid ""
+"Could not run the diff executable \"%1$s\".  You may need to set the \"%2$s"
+"\" config value."
+msgstr ""
+
+# Link displayed in commitdiff view, when the user has filtered
+# the display to a single file using the list of changed files.
+# This will go back to showing all files in the commitdiff
+#: templates/commitdiff.tpl
+msgid "(show all)"
+msgstr ""
+
+# Message displayed when diffing two binary files.
+# %1$s: the filename of the first file
+# %2$s: the filename of the second file
+#: include/git/FileDiff.class.php:810
+#, php-format
+msgid "Binary files %1$s and %2$s differ"
+msgstr ""
+
+# Used to label the url of the website of the project
+#: templates/project.tpl
+msgid "website"
+msgstr ""
+
+# This is the name of YOUR language, in your language.
+# Don't just translate the word "English".
+# This will be displayed as a choice in the language picker for your language.
+# You want this in your native language so speakers of your language
+# will recognize it.  For example, a french translation would translate
+# this as "Français".
+#: include/Resource.class.php:121
+msgid "English"
+msgstr "Deutsch"
+

--- a/locale/fr_FR/gitphp.po
+++ b/locale/fr_FR/gitphp.po
@@ -652,4 +652,84 @@
 msgid "set"
 msgstr "choisir"
 
-
+# Caption for the Atom button for a project
+# Atom is a standard web feed format
+#: templates/projectbase.tpl
+msgid "Atom"
+msgstr ""
+
+# Used as the title of the Atom controller
+# Atom is a standard web feed format
+#: include/controller/Controller_Feed.class.php:97
+msgid "atom"
+msgstr ""
+
+# Used as an error message when memcache is turned
+# on without the appropriate PHP extension installed
+#: include/smartyplugins/cacheresource.memcache.php:85
+msgid ""
+"The Memcached or Memcache PHP extension is required for Memcache support"
+msgstr ""
+
+# Message when searching the project list, and nothing is found
+# %1: the search string entered
+#: templates/jsconst.tpl
+#: templates/projectlist.tpl
+msgid "No matches found for \"%1\""
+msgstr ""
+
+# Label for the field to search the project list
+#: templates/projectlist.tpl
+msgid "Search projects"
+msgstr ""
+
+# Error message displayed when the git executable isn't found or doesn't work
+# %1$s: the git executable the system is trying to run
+# %2$s: the config value the user needs to set to specify the correct path
+#: index.php:140
+#, php-format
+msgid ""
+"Could not run the git executable \"%1$s\".  You may need to set the \"%2$s\" "
+"config value."
+msgstr ""
+
+# Error message displayed when the diff executable isn't found or doesn't work
+# %1$s: the diff executable the system is trying to run
+# %2$s: the config value the user needs to set to specify the correct path
+#: index.php:145
+#, php-format
+msgid ""
+"Could not run the diff executable \"%1$s\".  You may need to set the \"%2$s"
+"\" config value."
+msgstr ""
+
+# Link displayed in commitdiff view, when the user has filtered
+# the display to a single file using the list of changed files.
+# This will go back to showing all files in the commitdiff
+#: templates/commitdiff.tpl
+msgid "(show all)"
+msgstr ""
+
+# Message displayed when diffing two binary files.
+# %1$s: the filename of the first file
+# %2$s: the filename of the second file
+#: include/git/FileDiff.class.php:810
+#, php-format
+msgid "Binary files %1$s and %2$s differ"
+msgstr ""
+
+# Used to label the url of the website of the project
+#: templates/project.tpl
+msgid "website"
+msgstr ""
+
+# This is the name of YOUR language, in your language.
+# Don't just translate the word "English".
+# This will be displayed as a choice in the language picker for your language.
+# You want this in your native language so speakers of your language
+# will recognize it.  For example, a french translation would translate
+# this as "Français".
+#: include/Resource.class.php:121
+msgid "English"
+msgstr "Français"
+

--- a/locale/gitphp.pot
+++ b/locale/gitphp.pot
@@ -6,9 +6,9 @@
 #, fuzzy
 msgid ""
 msgstr ""
-"Project-Id-Version: GitPHP 0.2.4\n"
+"Project-Id-Version: GitPHP 0.2.6\n"
 "Report-Msgid-Bugs-To: xiphux@gmail.com\n"
-"POT-Creation-Date: 2011-08-25 20:54-0500\n"
+"POT-Creation-Date: 2012-03-21 20:43-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -54,14 +54,14 @@
 msgstr ""
 
 # Used as link to download a copy of the files in a given commit
+#: templates/jsconst.tpl
 #: templates/search.tpl
 #: templates/commit.tpl
 #: templates/taglist.tpl
-#: templates/header.tpl
 #: templates/treelist.tpl
 #: templates/projectlist.tpl
 #: templates/shortloglist.tpl
-#: include/controller/Controller_Snapshot.class.php:92
+#: include/controller/Controller_Snapshot.class.php:94
 msgid "snapshot"
 msgstr ""
 
@@ -76,10 +76,10 @@
 #: templates/commit.tpl
 #: templates/nav.tpl
 #: templates/taglist.tpl
-#: templates/header.tpl
 #: templates/log.tpl
 #: templates/history.tpl
 #: templates/shortloglist.tpl
+#: templates/projectbase.tpl
 #: include/controller/Controller_Commit.class.php:79
 msgid "commit"
 msgstr ""
@@ -97,7 +97,7 @@
 #: templates/tag.tpl
 #: templates/commit.tpl
 #: templates/committip.tpl
-#: templates/header.tpl
+#: templates/projectbase.tpl
 msgid "author"
 msgstr ""
 
@@ -161,7 +161,7 @@
 # The committer is the person who put the commit into this project
 #: templates/commit.tpl
 #: templates/committip.tpl
-#: templates/header.tpl
+#: templates/projectbase.tpl
 msgid "committer"
 msgstr ""
 
@@ -294,20 +294,21 @@
 msgstr ""
 
 # Link back to the list of projects
-#: templates/header.tpl
-#: include/controller/ControllerBase.class.php:257
+#: templates/main.tpl
+#: templates/projectbase.tpl
+#: include/controller/ControllerBase.class.php:270
 #: include/controller/Controller_ProjectList.class.php:94
 msgid "projects"
 msgstr ""
 
 # Used as a search type, to search the contents of files in the project
-#: templates/header.tpl
+#: templates/projectbase.tpl
 #: include/git/Blob.class.php:178
 msgid "file"
 msgstr ""
 
 # Used as title for search page, and also is the label for the search box
-#: templates/header.tpl
+#: templates/projectbase.tpl
 #: include/controller/Controller_Search.class.php:93
 msgid "search"
 msgstr ""
@@ -445,7 +446,7 @@
 
 # Used as the title of the rss controller
 # rss is a standard web feed format
-#: include/controller/Controller_Feed.class.php:91
+#: include/controller/Controller_Feed.class.php:92
 msgid "rss"
 msgstr ""
 
@@ -457,7 +458,7 @@
 # Error message when user tries to access a project that doesn't exist
 # %1$s: the project the user tried to access
 #: include/controller/Controller_Snapshot.class.php:44
-#: include/controller/ControllerBase.class.php:93
+#: include/controller/ControllerBase.class.php:101
 #, php-format
 msgid "Invalid project %1$s"
 msgstr ""
@@ -522,28 +523,28 @@
 # Error message when user specifies a path for a project root or project, but the path given isn't a directory
 # %1$s: the path the user specified
 #: include/git/ProjectListDirectory.class.php:47
-#: include/git/Project.class.php:326
+#: include/git/Project.class.php:338
 #, php-format
 msgid "%1$s is not a directory"
 msgstr ""
 
 # Error message when a path specified in the config is not a git repository
 # %1$s: the specified path
-#: include/git/Project.class.php:330
+#: include/git/Project.class.php:342
 #, php-format
 msgid "%1$s is not a git repository"
 msgstr ""
 
 # Error message when a path specified is using '..' to break out of the project root (a hack attempt)
 # %1$s: The specified path
-#: include/git/Project.class.php:334
+#: include/git/Project.class.php:346
 #, php-format
 msgid "%1$s is attempting directory traversal"
 msgstr ""
 
 # Error message when a path specified is outside of the project root
 # %1$s: The specified path
-#: include/git/Project.class.php:340
+#: include/git/Project.class.php:352
 #, php-format
 msgid "%1$s is outside of the projectroot"
 msgstr ""
@@ -591,7 +592,7 @@
 
 # Error message when a hash specified in a URL isn't a valid git hash
 # %1$s: the hash entered
-#: include/git/Pack.class.php:80 include/git/GitObject.class.php:107
+#: include/git/Pack.class.php:71 include/git/GitObject.class.php:137
 #, php-format
 msgid "Invalid hash %1$s"
 msgstr ""
@@ -666,24 +667,24 @@
 
 # Error message when user hasn't defined a project root in the config
 # "projectroot" refers to a root directory where the user's git projects are stored
-#: index.php:125
+#: index.php:132
 msgid "A projectroot must be set in the config"
 msgstr ""
 
 # Caption for the rss button for a project
 # rss is a standard web feed format
-#: templates/footer.tpl
+#: templates/projectbase.tpl
 msgid "RSS"
 msgstr ""
 
 # Caption for the OPML button on the project list
 # OPML is a standard XML outline format
-#: templates/footer.tpl
+#: templates/projectlist.tpl
 msgid "OPML"
 msgstr ""
 
 # Caption for the button to get a plaintext list of projects
-#: templates/footer.tpl
+#: templates/projectlist.tpl
 msgid "TXT"
 msgstr ""
 
@@ -713,48 +714,48 @@
 msgstr ""
 
 # Used as an alternate text on javascript "loading" images
-#: templates/header.tpl
+#: templates/jsconst.tpl
 msgid "Loading…"
 msgstr ""
 
 # Used as a loading message while blame data is being pulled from the server
-#: templates/header.tpl
+#: templates/jsconst.tpl
 msgid "Loading blame data…"
 msgstr ""
 
 # Used as a label by the language selector drop-down box
-#: templates/header.tpl
+#: templates/main.tpl
 msgid "language:"
 msgstr ""
 
 # Used as a button by the language selector drop-down box to set the
 # language to the user's choice
-#: templates/header.tpl
+#: templates/main.tpl
 msgid "set"
 msgstr ""
 
 # Caption for the Atom button for a project
 # Atom is a standard web feed format
-#: templates/footer.tpl
+#: templates/projectbase.tpl
 msgid "Atom"
 msgstr ""
 
 # Used as the title of the Atom controller
 # Atom is a standard web feed format
-#: include/controller/Controller_Feed.class.php:96
+#: include/controller/Controller_Feed.class.php:97
 msgid "atom"
 msgstr ""
 
 # Used as an error message when memcache is turned
 # on without the appropriate PHP extension installed
-#: include/cache/Memcache.class.php:103
+#: include/smartyplugins/cacheresource.memcache.php:85
 msgid ""
 "The Memcached or Memcache PHP extension is required for Memcache support"
 msgstr ""
 
 # Message when searching the project list, and nothing is found
 # %1: the search string entered
-#: templates/header.tpl
+#: templates/jsconst.tpl
 #: templates/projectlist.tpl
 msgid "No matches found for \"%1\""
 msgstr ""
@@ -767,7 +768,7 @@
 # Error message displayed when the git executable isn't found or doesn't work
 # %1$s: the git executable the system is trying to run
 # %2$s: the config value the user needs to set to specify the correct path
-#: index.php:133
+#: index.php:140
 #, php-format
 msgid ""
 "Could not run the git executable \"%1$s\".  You may need to set the \"%2$s\" "
@@ -777,7 +778,7 @@
 # Error message displayed when the diff executable isn't found or doesn't work
 # %1$s: the diff executable the system is trying to run
 # %2$s: the config value the user needs to set to specify the correct path
-#: index.php:138
+#: index.php:145
 #, php-format
 msgid ""
 "Could not run the diff executable \"%1$s\".  You may need to set the \"%2$s"
@@ -804,3 +805,13 @@
 msgid "website"
 msgstr ""
 
+# This is the name of YOUR language, in your language.
+# Don't just translate the word "English".
+# This will be displayed as a choice in the language picker for your language.
+# You want this in your native language so speakers of your language
+# will recognize it.  For example, a french translation would translate
+# this as "Français".
+#: include/Resource.class.php:121
+msgid "English"
+msgstr ""
+

--- a/locale/ja_JP/gitphp.po
+++ b/locale/ja_JP/gitphp.po
@@ -735,3 +735,13 @@
 msgid "website"
 msgstr "website"
 
+# This is the name of YOUR language, in your language.
+# Don't just translate the word "English".
+# This will be displayed as a choice in the language picker for your language.
+# You want this in your native language so speakers of your language
+# will recognize it.  For example, a french translation would translate
+# this as "Français".
+#: include/Resource.class.php:121
+msgid "English"
+msgstr "日本語"
+

--- a/locale/ru_RU/gitphp.po
+++ b/locale/ru_RU/gitphp.po
@@ -689,4 +689,53 @@
 msgid "Search projects"
 msgstr "Поиск проектов"
 
-
+# Error message displayed when the git executable isn't found or doesn't work
+# %1$s: the git executable the system is trying to run
+# %2$s: the config value the user needs to set to specify the correct path
+#: index.php:140
+#, php-format
+msgid ""
+"Could not run the git executable \"%1$s\".  You may need to set the \"%2$s\" "
+"config value."
+msgstr ""
+
+# Error message displayed when the diff executable isn't found or doesn't work
+# %1$s: the diff executable the system is trying to run
+# %2$s: the config value the user needs to set to specify the correct path
+#: index.php:145
+#, php-format
+msgid ""
+"Could not run the diff executable \"%1$s\".  You may need to set the \"%2$s"
+"\" config value."
+msgstr ""
+
+# Link displayed in commitdiff view, when the user has filtered
+# the display to a single file using the list of changed files.
+# This will go back to showing all files in the commitdiff
+#: templates/commitdiff.tpl
+msgid "(show all)"
+msgstr ""
+
+# Message displayed when diffing two binary files.
+# %1$s: the filename of the first file
+# %2$s: the filename of the second file
+#: include/git/FileDiff.class.php:810
+#, php-format
+msgid "Binary files %1$s and %2$s differ"
+msgstr ""
+
+# Used to label the url of the website of the project
+#: templates/project.tpl
+msgid "website"
+msgstr ""
+
+# This is the name of YOUR language, in your language.
+# Don't just translate the word "English".
+# This will be displayed as a choice in the language picker for your language.
+# You want this in your native language so speakers of your language
+# will recognize it.  For example, a french translation would translate
+# this as "Français".
+#: include/Resource.class.php:121
+msgid "English"
+msgstr "Русский"
+

--- a/locale/zh_CN/gitphp.po
+++ b/locale/zh_CN/gitphp.po
@@ -700,4 +700,33 @@
 msgid "Could not run the diff executable \"%1$s\".  You may need to set the \"%2$s\" config value."
 msgstr "不能运行比较程序 \"%1$s\". 你需要在配置文件中配置 \"%2$s\"项."
 
-
+# Link displayed in commitdiff view, when the user has filtered
+# the display to a single file using the list of changed files.
+# This will go back to showing all files in the commitdiff
+#: templates/commitdiff.tpl
+msgid "(show all)"
+msgstr ""
+
+# Message displayed when diffing two binary files.
+# %1$s: the filename of the first file
+# %2$s: the filename of the second file
+#: include/git/FileDiff.class.php:810
+#, php-format
+msgid "Binary files %1$s and %2$s differ"
+msgstr ""
+
+# Used to label the url of the website of the project
+#: templates/project.tpl
+msgid "website"
+msgstr ""
+
+# This is the name of YOUR language, in your language.
+# Don't just translate the word "English".
+# This will be displayed as a choice in the language picker for your language.
+# You want this in your native language so speakers of your language
+# will recognize it.  For example, a french translation would translate
+# this as "Français".
+#: include/Resource.class.php:121
+msgid "English"
+msgstr "中文简体"
+

--- a/locale/zz_Debug/gitphp.po
+++ b/locale/zz_Debug/gitphp.po
@@ -651,4 +651,84 @@
 msgid "set"
 msgstr "{sét•}"
 
-
+# Caption for the Atom button for a project
+# Atom is a standard web feed format
+#: templates/projectbase.tpl
+msgid "Atom"
+msgstr ""
+
+# Used as the title of the Atom controller
+# Atom is a standard web feed format
+#: include/controller/Controller_Feed.class.php:97
+msgid "atom"
+msgstr ""
+
+# Used as an error message when memcache is turned
+# on without the appropriate PHP extension installed
+#: include/smartyplugins/cacheresource.memcache.php:85
+msgid ""
+"The Memcached or Memcache PHP extension is required for Memcache support"
+msgstr ""
+
+# Message when searching the project list, and nothing is found
+# %1: the search string entered
+#: templates/jsconst.tpl
+#: templates/projectlist.tpl
+msgid "No matches found for \"%1\""
+msgstr ""
+
+# Label for the field to search the project list
+#: templates/projectlist.tpl
+msgid "Search projects"
+msgstr ""
+
+# Error message displayed when the git executable isn't found or doesn't work
+# %1$s: the git executable the system is trying to run
+# %2$s: the config value the user needs to set to specify the correct path
+#: index.php:140
+#, php-format
+msgid ""
+"Could not run the git executable \"%1$s\".  You may need to set the \"%2$s\" "
+"config value."
+msgstr ""
+
+# Error message displayed when the diff executable isn't found or doesn't work
+# %1$s: the diff executable the system is trying to run
+# %2$s: the config value the user needs to set to specify the correct path
+#: index.php:145
+#, php-format
+msgid ""
+"Could not run the diff executable \"%1$s\".  You may need to set the \"%2$s"
+"\" config value."
+msgstr ""
+
+# Link displayed in commitdiff view, when the user has filtered
+# the display to a single file using the list of changed files.
+# This will go back to showing all files in the commitdiff
+#: templates/commitdiff.tpl
+msgid "(show all)"
+msgstr ""
+
+# Message displayed when diffing two binary files.
+# %1$s: the filename of the first file
+# %2$s: the filename of the second file
+#: include/git/FileDiff.class.php:810
+#, php-format
+msgid "Binary files %1$s and %2$s differ"
+msgstr ""
+
+# Used to label the url of the website of the project
+#: templates/project.tpl
+msgid "website"
+msgstr ""
+
+# This is the name of YOUR language, in your language.
+# Don't just translate the word "English".
+# This will be displayed as a choice in the language picker for your language.
+# You want this in your native language so speakers of your language
+# will recognize it.  For example, a french translation would translate
+# this as "Français".
+#: include/Resource.class.php:121
+msgid "English"
+msgstr "Gibberish"
+

comments