import locale


def local_decode(value):
    """Decode bytes into a string by using the system preferred encoding.
    Defaults to utf8 otherwise."""
    encoding = locale.getpreferredencoding(False)
    try:
        return value.decode(encoding)
    except LookupError:
        return value.decode('utf8', errors='replace')