Repository: getpelican/pelican

Issue:
Quickstart locale error: 'NoneType' object has no attribute 'split'
Pelican version: 594b9c96 (installed with `pip install -e "git+https://github.com/getpelican/pelican.git#egg=pelican"`)
Python: 2.7.12 Windows x64 (within a virtual environment)
Using:
> blinker (1.4)
docutils (0.12)
feedgenerator (1.9)
Jinja2 (2.8)
Markdown (2.6.7)
MarkupSafe (0.23)
pelican (3.6.4.dev0, d:\documents\pelican\src\pelican)
pip (8.1.2)
Pygments (2.1.3)
python-dateutil (2.5.3)
pytz (2016.7)
setuptools (28.7.1)
six (1.10.0)
smartypants (1.8.6)
typogrify (2.0.7)
Unidecode (0.4.19)
wheel (0.30.0a0)

When invoking `pelican-quickstart`, I am getting the following stacktrace:

>(Pelican) D:\Documents\Pelican>pelican-quickstart
Traceback (most recent call last):
  File "D:\Documents\Pelican\Scripts\pelican-quickstart-script.py", line 11, in <module>
    load_entry_point('pelican', 'console_scripts', 'pelican-quickstart')()
  File "d:\documents\pelican\lib\site-packages\pkg_resources\__init__.py", line 564, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "d:\documents\pelican\lib\site-packages\pkg_resources\__init__.py", line 2608, in load_entry_point
    return ep.load()
  File "d:\documents\pelican\lib\site-packages\pkg_resources\__init__.py", line 2268, in load
    return self.resolve()
  File "d:\documents\pelican\lib\site-packages\pkg_resources\__init__.py", line 2274, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "d:\documents\pelican\src\pelican\pelican\tools\pelican_quickstart.py", line 52, in <module>
    'lang': locale.getlocale()[0].split('_')[0],
AttributeError: 'NoneType' object has no attribute 'split'




Discussion:
Perhaps related to c361246, which was merged via #1972 and was meant to address #1971.

@nstinus: Any thoughts on this?

See also https://docs.python.org/2/library/locale.html, https://bugs.python.org/issue6203 and https://bugs.python.org/issue12699.
In other words: `locale.getlocale()` returns `(None, None)`. See below:

> (Pelican) D:\Documents\Pelican>python
> Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (
> AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> 
> > > import locale
> > > locale.getlocale()
> > > (None, None)
> > > locale.getdefaultlocale()
> > > ('es_AR', 'cp1252')
> > > locale.setlocale(locale.LC_ALL, '');
> > > 'Spanish_Argentina.1252'
> > > locale.getlocale()
> > > ('Spanish_Argentina', '1252')

I am having the same problem with python 3. 

I believe it is because line 26 of the [commit](https://github.com/amyspark/pelican/commit/70373a1c473ee3863b7b64ec308ade8e91b4e3e7#diff-52fe2de2a8486e716ec2398752ead4ddR26) to fix this issue (#2043) should be changed from `sys.version_info.major == 2` to `sys.version_info.major >= 2` 

Changing that line fixes the problem for me. I am going to try and write a pull request. I am not sure how that works when the issue is technically closed. 

```
[site_tmp] C:\tmp>conda list
# packages in environment at C:\Anaconda2\envs\site_tmp:
#
blinker                   1.4                      py35_0    conda-forge
certifi                   2016.9.26                py35_0    conda-forge
docutils                  0.12                     py35_2    defaults
feedgenerator             1.9                      py35_0    conda-forge
ghp-import                0.4.1                    py35_0    conda-forge
jinja2                    2.8                      py35_1    conda-forge
markdown                  2.6.7                    py35_0    defaults
markupsafe                0.23                     py35_2    defaults
pelican                   3.7.0                    py35_0    conda-forge
pip                       9.0.1                    py35_1    defaults
pygments                  2.1.3                    py35_1    conda-forge
python                    3.5.2                         2    conda-forge
python-dateutil           2.6.0                    py35_0    conda-forge
pytz                      2016.10                  py35_0    conda-forge
setuptools                32.1.0                   py35_0    conda-forge
six                       1.10.0                   py35_1    conda-forge
unidecode                 0.04.19                  py35_0    conda-forge
vs2015_runtime            14.0.25420                    0    conda-forge
wheel                     0.29.0                   py35_0    defaults
wincertstore              0.2                      py35_0    conda-forge

[site_tmp] C:\tmp>pelican-quickstart
Traceback (most recent call last):
  File "C:\Anaconda2\envs\site_tmp\Scripts\pelican-quickstart-script.py", line 3, in <module>
    import pelican.tools.pelican_quickstart
  File "C:\Anaconda2\envs\site_tmp\lib\site-packages\pelican\tools\pelican_quickstart.py", line 52, in <module>
    'lang': locale.getlocale()[0].split('_')[0],
AttributeError: 'NoneType' object has no attribute 'split'

[site_tmp] C:\tmp>
```

Resolving patch:
diff --git a/pelican/tools/pelican_quickstart.py b/pelican/tools/pelican_quickstart.py
--- a/pelican/tools/pelican_quickstart.py
+++ b/pelican/tools/pelican_quickstart.py
@@ -21,8 +21,12 @@
 
 from pelican import __version__
 
-if (sys.version_info.major == 2):
-    locale.setlocale(locale.LC_ALL, '')
+locale.setlocale(locale.LC_ALL, '')
+_DEFAULT_LANGUAGE = locale.getlocale()[0]
+if _DEFAULT_LANGUAGE is None:
+    _DEFAULT_LANGUAGE = 'English'
+else:
+    _DEFAULT_LANGUAGE = _DEFAULT_LANGUAGE.split('_')[0]
 
 _TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               "templates")
@@ -51,7 +55,7 @@
     'github_pages_branch': _GITHUB_PAGES_BRANCHES['project'],
     'default_pagination': 10,
     'siteurl': '',
-    'lang': locale.getlocale()[0].split('_')[0],
+    'lang': _DEFAULT_LANGUAGE,
     'timezone': _DEFAULT_TIMEZONE
 }
 


Test patch: